Skip to content

Instantly share code, notes, and snippets.

@realmayus
Last active November 6, 2019 20:12
Show Gist options
  • Save realmayus/314063135e4cab6f1ab995aa0a9d8f9e to your computer and use it in GitHub Desktop.
Save realmayus/314063135e4cab6f1ab995aa0a9d8f9e to your computer and use it in GitHub Desktop.
A simple self-written cipherer and decipherer written in python 3.x
alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
mode = input("What mode? (c)ipher / (d)ecipher: ")
if mode == "c":
offset = input("Enter offset: ")
if not offset.isdigit():
print("\nOffset must be a positive Integer! Exiting...")
exit()
input = input("\nEnter text to offset with " + offset + ": ")
input = input.lower()
print("\nCiphering '" + input + "'....\n")
output = ""
for input_char in input:
if not input_char == " ":
x = (int(alphabet.index(input_char)) + int(offset)) % len(alphabet)
output = output + alphabet[x]
else:
output = output + " "
print("Your ciphered String is: \n" + output + "")
elif mode == "d":
offset = input("Enter offset: ")
if not offset.isdigit():
print("\nOffset must be a positive Integer! Exiting...")
exit()
input = input("\nEnter text to offset with " + offset + ": ")
input = input.lower()
print("\nCiphering '" + input + "'....\n")
output = ""
for input_char in input:
if not input_char == " ":
x = (int(alphabet.index(input_char)) - int(offset)) % len(alphabet)
output = output + alphabet[x]
else:
output = output + " "
print("Your deciphered String is: \n" + output + "")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment