# Program to decrypt using Caesar cipher # ECS 10, Winter 2012 # Matt Bishop, Mar. 7, 2012 import string # # this corresponds to a key of 'D' ('A' = 0, ... 'Z' = 25) # key = 3 # # ask user for input message (plaintext) # cipher = input("Enter your message here: ") # # initialize output (plaintext) # plain = "" # # decipher each character and append it to current plaintext # for i in cipher: # leave non-letters alone if i in "ABCDEFGHIJKLMNOPQRSTUVWXYZ": # map the letter into 0 . . 25 n = ord(i) - ord('A') # shift it n = (n - key) % 26 # map it back into a letter lett = chr(ord('A') + n) elif i in "abcdefghijklmnopqrstuvwxyz": # map the letter into 0 . . 25 n = ord(i) - ord('a') # shift it n = (n - key) % 26 # map it back into a letter lett = chr(ord('a') + n) else: lett = i # now append it plain = plain + lett # # print it, surrounded by quotes # print("\"%s\"" % plain)