Last active
May 4, 2017 22:41
-
-
Save algrant/e12fcb86d85c1bc38c45599644e701e9 to your computer and use it in GitHub Desktop.
simple caesar shift in python
This file contains 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
alphabet = 'abcdefghijklmnopqrstuvwxyz' | |
def shift(text, n): | |
answer = '' | |
for c in text: | |
if c in alphabet: | |
answer += alphabet[(alphabet.index(c)+n)%26] | |
continue | |
answer += c | |
return answer | |
def compare(text1, text2): | |
for c1, c2 in zip(text1, text2): | |
diff = alphabet.index(c1) - alphabet.index(c2) | |
if diff < 0: | |
diff += 26 | |
opp = diff - 26 | |
print opp, '\t', diff |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment