Last active
September 27, 2018 02:20
-
-
Save benrules2/2f16c2ba89fbf5357c1767f757a124d5 to your computer and use it in GitHub Desktop.
Shift Cipher
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
class ShiftCipher: | |
def __init__(self, N = 13): | |
[...] | |
def encrypt_message(self, message): | |
encrypted = "" | |
#lowercase the message as alphabets are lowercase | |
message = message.lower() | |
for letter in message: | |
if self.original_alphabet.count(letter) > 0: | |
#if the letter exists in original alphabet, find the index and add encrypted form | |
index = self.original_alphabet.index(letter) | |
encrypted += self.cipher_alphabet[index] | |
else: | |
#if it does not exist in cipher alphabet, do not change the character | |
encrypted += letter | |
return encrypted | |
def decrypt_message(self, message): | |
decrypted = "" | |
#lowercase the message as alphabets are lowercase | |
message = message.lower() | |
for letter in message: | |
if self.original_alphabet.count(letter) > 0: | |
#if the letter exists in original alphabet, find the index and add decrypted form | |
index = self.cipher_alphabet.index(letter) | |
decrypted += self.original_alphabet[index] | |
else: | |
#if it does not exist in original alphabet, do not change the character | |
decrypted += letter | |
return decrypted | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment