Skip to content

Instantly share code, notes, and snippets.

@neerajvashistha
Created September 26, 2018 11:21
Show Gist options
  • Save neerajvashistha/109b8897390d9e7742a8e55f7b7f559c to your computer and use it in GitHub Desktop.
Save neerajvashistha/109b8897390d9e7742a8e55f7b7f559c to your computer and use it in GitHub Desktop.
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