Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote