Created
November 1, 2014 17:07
-
-
Save saurabhmathur96/75bdcfa08edeb9b7336a to your computer and use it in GitHub Desktop.
An Implementation of the caesar-cipher and rot13
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
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