Skip to content

Instantly share code, notes, and snippets.

@saurabhmathur96
Created November 1, 2014 17:07
Show Gist options
  • Save saurabhmathur96/75bdcfa08edeb9b7336a to your computer and use it in GitHub Desktop.
Save saurabhmathur96/75bdcfa08edeb9b7336a to your computer and use it in GitHub Desktop.
An Implementation of the caesar-cipher and rot13
def encipher(letter,shift):
letter = letter.upper() # just to make sure the letter is uppercase
ascii_letter = ord(letter)
ascii_A = ord('A')
pos_letter = ascii_letter - ascii_A
shifted_pos_letter = ( pos_letter + shift )%26
asc_ciphered_letter = shifted_pos_letter + ascii_A
return chr(asc_ciphered_letter)
def encipher_text(text,shift):
ciphertext = ''
for c in text:
if c.isalpha():
ciphertext += encipher(c,shift)
else :
ciphertext += c
return ciphertext
def rot13(text):
return encipher_text(text,13)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment