シーザー暗号を作ろうとしていて、問題があります。Python Caesar暗号アスキースペースを追加する
これは完全に機能しますが、入力された単語にスペースを追加します。あなたがスペースを含む文を入力した場合。それは単に暗号化されているときにスペースの代わりに=を表示します。誰も私がスペースを印刷するようにこれを修正するのを助けることができますか?あなたの条件に近い見てみる必要がある
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