摩斯的解密和加密
dict_ori = {'.-': 'A',
'-...': 'B',
'-.-.': 'C',
'-..':'D',
'.':'E',
'..-.':'F',
'--.': 'G',
'....': 'H',
'..': 'I',
'.---':'J',
'-.-': 'K',
'.-..': 'L',
'--': 'M',
'-.': 'N',
'---': 'O',
'.--.': 'P',
'--.-': 'Q',
'.-.': 'R',
'...': 'S',
'-': 'T',
'..-': 'U',
'...-': 'V',
'.--': 'W',
'-..-': 'X',
'-.--': 'Y',
'--..': 'Z',
'.----': '1',
'..---': '2',
'...--': '3',
'....-': '4',
'.....': '5',
'-....': '6',
'--...': '7',
'---..': '8',
'----.': '9',
'-----': '0',
'..--..': '?',
'-..-.': '/',
'-.--.-': '()',
'-....-': '-',
'.-.-.-': '.'
};
dict_new = {value:key for key,value in dict_ori.items()}
x = int(input("choose encryption or decryption"))
a = input("input the string:")
s = a.split(" ")
if x == 0:
for item in s:
print(dict_ori[item],end='')
elif x == 1:
for item in s:
print(dict_new[item],end='')
else:
print("please choice the 0 or 1")
通过字典的互换实现了加密和解密的结合
浙公网安备 33010602011771号