我正在研究ceaser密码的变体。当我输入加密的消息时,我的decrypt()
函数应该保持解密不同的旋转值,直到一个常用的单词,例如。弹出“the”或“time”或“attack”。出于测试目的,我使用诸如“继续攻击基础”之类的消息,因此当any(word.upper() in plainText for word in subStrings)
部件运行时,它应该返回true,但它不会。我当前的代码如下:any()不返回true?
def decrypt(encryptedMessage):
alphanumericAlphabet = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"] # List of every letter in the alphabet
message = (str(encryptedMessage).strip("\n")).upper()
subStrings = ["The", "Base", "Proceed", "North", "West", "South", "East", "Hours", "Dawn", "Attack", "Defend", "Shoot", "Bearing", "Enemy", "Position", "Move", "That", "Fast", "Time", "Rise", "Loss", "Win", "Victory"]
plainText = ""
messageFound = False
rotationValue = 0
while messageFound != True:
if any(word.upper() in plainText for word in subStrings):
messageFound = True
else:
plainText = ""
for character in message:
cipherIndex = alphanumericAlphabet.index(character.upper())
plainIndex = cipherIndex - rotationValue
if plainIndex < 0:
plainIndex += 36
plainText += alphanumericAlphabet[plainIndex]
rotationValue += 1
print "Decrypted Message:", plainText, "\n", "Rotation:", rotationValue
return plainText, rotationValue
@ user2357112是的,因为我的消息将是大写的,我需要我的子字符串也为大写所以我使用'.upper()' –
此外,消息是否不包含任何其他通配符,如#$〜? – skrubber
请不要更改您的标题或您的问题的内容 –