这是我的任务: 编写一个解密秘密消息的程序。解密炒字母?
它应该首先提示用户输入拼音字母。然后它应该要求秘密消息。最后,它输出未加扰的版本。
请注意,正好有26个字符为乱码字母输入。所有的字母字符都被翻译成它们的解码等价物(这将需要一个WHILE循环),而所有其他的非字母字符应该与没有翻译时一样输出。
这是我到目前为止的代码:
decrypt = ["*"] * 26
scram_alphabet = input("Please input the scrambled alphabet in order: ")
while len(scram_alphabet) != 26:
scram_alphabet = input("Please input the scrambled alphabet in order. The alphabet must have 26 characters: ")
num = 0
for each_letter in scram_alphabet:
decrypt[num] = ord(each_letter)
num = num + 1
print()
print()
msg = input("Now input your scrambled message: ")
print()
print()
num = 0
alphabet = [" "] * 26
for letter in range (26):
alphabet[letter] = letter + 65
while num < 26:
alphabet [num] = decrypt [num]
print(chr(alphabet[num]))
num = num + 1
for alpha in msg.upper():
if alpha < "A" or alpha > "Z":
print(alpha,end="")
else:
print(chr(decrypt[ ord(alpha) - 65 ]), end="")
我似乎无法弄清楚如何使用while循环解扰字母表。
目前如果我输入'XQHAJDENKLTCBZGUYFWVMIPSOR'作为字母和'VNKW KW BO 1WV WJHFJV BJWWXEJ!'作为秘密消息,该程序打印出乱码字母和一个“解读”消息,读取“IZTP TP QG 1PI PLNDLI QLPPSJL!”。解密的消息实际上是“这是我的第一个秘密消息!”
任何助手?
我以为你说你的课是在2天前,2天前结束。你还有功课吗? – user2357112
是。 hw在决赛后的第二天。 – user2680935