我正在尝试制作凯撒密码,但是遇到了问题。
它的运行非常完美,但是我想在输入的单词中添加空格。如果您输入带有空格的句子,则加密时只会打印出=而不是空格。有谁能帮我修复这个问题,以便它能够打印出空格?
这是我的代码:
word = input("What is the message you want to encrypt or decrypt :")
def circularShift(text, shift):
text = text.upper()
cipher = "Cipher = "
for letter in text:
shifted = ord(letter) + shift
if shifted < 65:
shifted += 26
if shifted > 90:
shifted -= 26
cipher += chr(shifted)
if text == (" "):
print(" ")
return cipher
print (word)
print ("The encoded and decoded message is:")
print ("")
print ("Encoded message = ")
print (circularShift(word , 3))
print ("Decoded message = ")
print (circularShift(word , -3))
print ("")
input('Press ENTER to exit')
string.ascii_letters
,我不知道它在那里 :D。 - Netwave