如何解决凯撒密码python解密
我在尝试解码加密消息时遇到问题。它几乎可以完美地解密所有内容,但特定的小写字母不能正确解密。虽然它在大写时有效。我做错了什么?
def decrypt():
print("Heres our Caeser Cipher Decryption program.")
encrpMsg = input("Enter the message you would like to decrypt: ").strip()
print()
decrpKey = int(input("Enter key to decrypt,a number 0-25: "))
decryptedMessage = ""
for i in range(len(encrpMsg)):
if ord(encrpMsg[i]) == 32:
decryptedMessage += chr(ord(encrpMsg[i]))
elif ((ord(encrpMsg[i]) - decrpKey) < 97 and ((ord(encrpMsg[i]) - decrpKey) > 90)):
temp = (ord(encrpMsg[i]))
decryptedMessage += chr(temp)
elif (ord(encrpMsg[i]) - decrpKey) <65:
temp = (ord(encrpMsg[i]) - decrpKey) + 26
decryptedMessage += chr(temp)
else:
decryptedMessage += chr(ord(encrpMsg[i]) - decrpKey)
print(decryptedMessage)
密钥:13 输出: ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmTUVWXYZhijklm 预期产出: ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。