Created
September 26, 2018 11:21
-
-
Save neerajvashistha/109b8897390d9e7742a8e55f7b7f559c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import string | |
alphabet = ' '+ string.ascii_lowercase | |
count = 0 | |
positions=dict() | |
for a in alphabet: | |
positions[a] = count | |
count = count + 1 | |
def shift_encode(message,key): | |
encoding_list = [] | |
for char in message: | |
position = positions[char] | |
encoded_position = (position + key) % 27 | |
encoding_list.append(alphabet[encoded_position]) | |
encoded_string = "".join(encoding_list) | |
return encoded_string | |
encoded_message = shift_encode(message,3) | |
print(encoded_message) | |
decode_message = shift_encode(encoded_message, -3) | |
print(decode_message) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment