我在做一个多胺基密码。我的代码正在运行,但它没有在最后打印“cyphertext”。我甚至试过测试for循环的各个部分,但都不会打印出来
import string
alpha = string.ascii_lowercase
message = input('Message:')
message = message.upper()
secretWord = input('Secret word:')
secretWord = secretWord.upper()
cypherText = ''
count = 0
for letter in message:
if letter in alpha:
shift = alpha.index(secretWord[count])
letterIndex = alpha.index(letter)
cypherLetter = alpha[(letterIndex+shift)%26]
cypherText = cypherText + cypherLetter
count = count+1
print(cypherText)
在代码中的任何地方都使用大写或小写:
输出:
您的消息是大写的,但是alpha是小写的,所以您在消息上迭代的字母永远不会出现在alpha
您还在循环外增加计数,这会导致常量偏移
将每个字符都设为大写,然后检查是否为小写字符。因为大写字符不是小写字符,所以它不会被加密
相关问题 更多 >
编程相关推荐