【发布时间】:2017-11-08 09:57:17
【问题描述】:
我正在尝试制作凯撒密码,但我遇到了问题。
它工作得很好,但我想在输入的单词中添加空格。如果你输入一个带有空格的句子。它只是在加密时打印出 = 而不是空格。谁能帮我解决这个问题,以便打印出空格?
这是我的代码:
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')
【问题讨论】: