I’m working with an old python exercise is to implement the caesar cipher, a simple encryption technique. Description of the methods can be found on the web (wikipedia) http://en.wikipedia.org/wiki/Caeser_cipher and the additional document.
In short, each letter is replaced by another letter (like a is replaced by b, b is replaced by c,. . . in case we are using a shift of one). You should write a python code who is able to crypt and decrypt an English sentence (the 26 letters) using this cipher. You program should take as input the size of the shift too (a number between 0 and 26).
How can I decrypt my message:) ?
message= raw_input("Please enter plaintext to Cipher: ") shift = int(raw_input("Please enter shift: ")) result = '' for letter in message: x = ord(letter) if letter.isalpha(): x = x + shift offset = 65 if letter.islower(): offset = 97 while x < offset: x += 26 while x > offset+25: x -= 26 result += chr(x) print result