Created
September 19, 2011 14:14
-
-
Save jithusunny/1226580 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
#Date: Sept 19, 2011 | |
#Filename: caesar.py | |
#Code for deciphering Caesar-Cipher | |
#Author: Jithu Sunny | |
#Blog: http://jithusunnyk.blogspot.com/ | |
#Email: jithusunnyk@gmail.com | |
def shift(str, n): | |
'''Forms the new string by shifting all characters in str by n places''' | |
new = '' | |
for c in str: | |
if c.isalpha(): | |
num = ord(c) + n | |
if c.islower(): | |
if num < 123: | |
new += chr(num) | |
else: | |
new += chr(num - 26) | |
elif c.isupper(): | |
if num < 91: | |
new += chr(num) | |
else: | |
new += chr(num - 26) | |
else: | |
new += c | |
return new | |
def combi(str): | |
'''Prints all 25 possible plain-messages''' | |
for i in range(1, 26): | |
print shift(str, i) | |
str = raw_input('Enter the cipher: ') | |
combi(str) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment