【发布时间】:2020-07-24 04:18:35
【问题描述】:
我正在尝试输入多个数字,例如
[106, 103, 110, 110, 113, 32, 121, 113, 116, 110, 102]
使用ord()进入解密,然后通过凯撒密码输入。凯撒密码有效,但我不知道如何使用chr(),但它表明当我输入数字时这是一个错误。
谢谢!
print("Decryption")
text = int(input("Enter encrypted numbers: \n"))
encrypt = chr(text)
decrp_key = int(input("Enter key:\n"))
decrypted_text = ""
for i in range(len(encrypt)):
if ord(encrypt[i]) == 32:
decrypted_text += chr(ord(encrypt[i]))
elif ((ord(encrypt[i]) - decrp_key) < 97) and ((ord(encrypt[i]) - decrp_key) > 90):
temp = (ord(encrypt[i]) - decrp_key) + 26
decrypted_text += chr(temp)
elif (ord(encrypt[i]) - decrp_key) < 65:
temp = (ord(encrypt[i]) - decrp_key) + 26
decrypted_text += chr(temp)
else:
decrypted_text += chr(ord(encrypt[i]) - decrp_key)
print("Decrypted Text: " + decrypted_text)```
【问题讨论】:
-
您能否指定您想要的输入/输出。您正在阅读单个 int,但您在描述中指的是整数列表。
-
我尝试将数字一起输入,然后使用 chr 将其转换为单词以便翻译为凯撒密码。这样我就可以将输出读取为单词。
-
提示:如果您需要数字列表,则将用户输入,但
append放入列表中。 -
ValueError: invalid literal for int() with base 10: '106, 103, 110, 110, 113, 32, 121, 113, 116, 110, 102' 这是我得到的错误
-
你不能在一次输入所有的数字,你必须
append他们到一个列表,storeNum= []然后追加到那个列表。