morse = [".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."]
digit = ['-----', '.----', '..---', '...--', '....-', '.....', '-....', '--...', '---..', '----.']
punctuation = {'.': '.-.-.-', ':': '---...', ',': '--..--', ';': '-.-.-.', '?': '..- -..', '=': '-...-', "'": '.----.', '/': '-..-.', '!': '-.-.--', '-': '-....-', '_': '..--.-', '"': '.-..-.', '(': '-.--.', ')': '-.--.-', '$': '...-..-', '&': '·-···', '@': '.--.-.', ' ': ''}
re_punctuation = dict(zip(punctuation.values(), punctuation.keys())) #键值对翻转
txt = input().split(' ')
for ch in txt:
if ch in morse:
new_ch = chr(morse.index(ch) + ord('a'))
print(new_ch, end='')
elif ch in digit:
new_ch = chr(digit.index(ch) + ord('0'))
print(new_ch, end='')
elif ch in re_punctuation.keys():
new_ch = re_punctuation[ch]
print(new_ch, end='')
else:
print(ch, end='')
#与加密相比,会用到index函数取下标,都借用了ASCII进行转换字符
#该解密还有缺点:解密后的字母都是小写,问题不大
清晰,易懂