题目描述
1、对输入的字符串进行加解密,并输出。
2、加密方法为:
当内容是英文字母时则用该英文字母的后一个字母替换,同时字母变换大小写,如字母a时则替换为B;字母Z时则替换为a;
当内容是数字时则把该数字加1,如0替换1,1替换2,9替换0;
其他字符不做变化。
3、解密方法为加密的逆过程。
本题含有多组样例输入。
输入描述:
输入说明
输入一串要加密的密码
输入一串加过密的密码
输出描述:
输出说明
输出加密后的字符
输出解密后的字符
示例1
输入
abcdefg
BCDEFGH
输出
BCDEFGH
abcdefg
代码实现:
import string
def func():
while True:
try:
str1 = string.ascii_uppercase
list1 = list(str1)
input1 = input()
input2 = input()
res1 = ""
for i in input1:
if i.isupper():
index = list1.index(i)+1
if index==len(list1):
index = 0
res1 +=str.lower(list1[index])
elif i.islower():
index = list1.index(str.upper(i))+1
if index==len(list1):
index = 0
res1 +=list1[index]
elif i.isdigit():
i = '0' if i =='9' else str(int(i) + 1 )
res1 += str(i)
else:
res1 += i
print(res1)
res2 = ''
for i in input2:
if i.isupper():
index = list1.index(i)-1
res2 += str.lower(list1[index])
elif i.islower():
index = list1.index(str.upper(i))-1
res2 += list1[index]
elif i.isdigit():
i = '9' if i =='0' else str(int(i) - 1 )
res2 += str(i)
else:
res2 +=i
print(res2)
except Exception as e:
#print(e)
break
if __name__ == '__main__':
func()