我正在尝试制作一个脚本,将消息的每个字母旋转 13 个字母,创建一个简单的密码。我的密码正确地旋转了字母,我遇到的问题是它只将它加密为大写字母。
例如,对于我输入“Hello!World”,它应该返回“Uryyb!Jbeyq”,但它返回“URYYB!JBEYQ”
uppercase = ['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']
lowercase = ['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']
ciphered = ""
for i in message:
if i.isalpha():
if i in uppercase: # checks if letter (i) is an upper case and treats it as such
letter = uppercase.index(i)
rotated = uppercase[(letter + 13) % 26] # used to loop through alphabet
ciphered = ciphered + rotated
else:
letter = lowercase.index(i)
rotated = uppercase[(letter + 13) % 26] # used to loop through alphabet
ciphered = ciphered + rotated
else:
ciphered = ciphered + i
return ciphered