Write a python program to decode text that was encoding using the Caesar cipher.
ID: 3670060 • Letter: W
Question
Write a python program to decode text that was encoding using the Caesar cipher. Caesar’s cihper works by shifting every letter in a piece of text three characters over, so “A” becomes “D”, “B” becomes “E”, and so on.
An example run of the program might look like:
Enter your cipher text: zhofrph!
The decoded phrase is: welcome!
An example run of the program might look like:
Enter your cipher text: l dp frro!
The decoded phrase is: I am cool!
Convert all text to lowercase before doing any conversion. All punctuation and spacing to go through unchanged.
Explanation / Answer
cipherText = raw_input("What is your cipherText? ")
shift = 3
def caesar(cipherText, shift):
plainText = ''
cipherText = cipherText.lower()
for ch in cipherText:
if ch.isalpha():
stayInAlphabet = ord(ch) - shift
if stayInAlphabet < ord('a'):
stayInAlphabet += 26
plainText+=(chr(stayInAlphabet))
else:
plainText+=(ch)
print plainText
caesar(cipherText, shift)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.