一、题目
二、示例
三、代码
dic1 = {'a':'B', 'b':'C', 'c':'D', 'd':'E', 'e':'F', 'f':'G',
'g':'H', 'h':'I', 'i':'J', 'j':'K', 'k':'L', 'l':'M',
'm':'N', 'n':'O', 'o':'P', 'p':'Q', 'q':'R', 'r':'S',
's':'T', 't':'U', 'u':'V', 'v':'W', 'w':'X', 'x':'Y',
'y':'Z', 'z':'A','A':'b', 'B':'c', 'C':'d', 'D':'e',
'E':'f', 'F':'g', 'G':'h', 'H':'i', 'I':'j', 'J':'k',
'K':'l', 'L':'m', 'M':'n', 'N':'o', 'O':'p', 'P':'q',
'Q':'r', 'R':'s', 'S':'t', 'T':'u', 'U':'v', 'V':'w',
'W':'x', 'X':'y', 'Y':'z', 'Z':'a',
'0':'1', '1':'2', '2':'3', '3':'4', '4':'5', '5':'6',
'6':'7', '7':'8', '8':'9', '9':'0'}
dic_1 = dict(map(reversed, dic1.items()))
def encodefun(s):
temp = []
for i in s:
temp.append(dic1[i])
return ''.join(temp)
def decodefun(s):
temp = []
for i in s:
temp.append(dic_1[i])
return ''.join(temp)
while True:
try:
e = input()
d = input()
print(encodefun(e))
print(decodefun(d))
except:
break
四、算法说明
按照加密的方式建立字典dic1
,然后翻转字典,建立解密的字典dic1
;
建立加密,解密函数,输出结果。
胡萝卜
2022年3月9日18:14:49
我不知道将去向何方,但我已在路上! |
---|
时光匆匆,虽未曾谋面,却相遇于斯,实在是莫大的缘分,感谢您的到访 ! |