900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > python中凯撒密码加密_凯撒密码加密

python中凯撒密码加密_凯撒密码加密

时间:2020-03-23 18:35:17

相关推荐

python中凯撒密码加密_凯撒密码加密

您似乎是在交互式提示中输入此代码,而不是将其保存为文件并运行它。如果是这样,那么当您使用input时,窗口将在允许您继续输入代码之前提示您输入。在plainText = input("python: ")

输入此行后,键入要加密的单词,然后按enter键。只有这样你才能写下这行:

^{pr2}$

在开始下一行code = ""之前,您应该输入所需的距离。在

作为一个风格技巧,我建议将提示文本从"python:"和"3:"改为类似“text to encrypt:”和“distance:”,这样用户就可以清楚地看到他应该输入什么。在

接下来,这里有一个缩进错误:if cipherValue > ord('z'):

cipherValue = ord('a') = distance - \

if条件后的行应该再缩进一级。在if cipherValue > ord('z'):

cipherValue = ord('a') = distance - \

接下来,在这些线路上有两个问题。在cipherValue = ord('a') = distance - \

(ord('z') - ordValue + 1)行继续符\后面不应该有空格。在任何情况下,最好是将整个表达式写在一行上,因为这行实际上不够长,不能分成两行。在

第二个等号是个打字错误。它应该是个加号。在

-cipherValue = ord('a') + distance - (ord('z') - ordValue + 1)

此时,您的程序应该运行时没有任何错误,但是它还没有产生任何输出。加密每个字符时,将其添加到code。然后在循环结束后打印它。在plainText = input("text to encrypt: ")

distance = int(input("distance: "))

code = ""

for ch in plainText:

ordValue = ord(ch)

cipherValue = ordValue + distance

if cipherValue > ord('z'):

cipherValue = ord('a') + distance - (ord('z') - ordValue + 1)

code = code + chr(cipherValue)

print(code)

#to do: write this to a file, or whatever else you want to do with it

这里,chr将数字cipherValue转换成它的等效字母。在

结果:text to encrypt: hacker

distance: 13

unpxre

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。