Skip to content

Instantly share code, notes, and snippets.

@algrant
Last active May 4, 2017 22:41
Show Gist options
  • Save algrant/e12fcb86d85c1bc38c45599644e701e9 to your computer and use it in GitHub Desktop.
Save algrant/e12fcb86d85c1bc38c45599644e701e9 to your computer and use it in GitHub Desktop.
simple caesar shift in python
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