Skip to content

Instantly share code, notes, and snippets.

@myrkvi
Last active August 29, 2015 13:56
Show Gist options
  • Save myrkvi/8944556 to your computer and use it in GitHub Desktop.
Save myrkvi/8944556 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
import sys
alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZÆØÅabcdefghijklmnopqrstuvwxyzæøå .,:;!?"
def encodeString(ab, sTE, sec):
finalString = ""
for x in sTE:
pos = ab.find(x)
nPos = pos + sec
if nPos >= len(ab):
nPos = nPos - len(ab)
finalString = finalString + ab[nPos]
return finalString
def decodeString(ab, sTE, sec):
finalString = ""
for x in sTE:
pos = ab.find(x)
nPos = pos - sec
if nPos < 0:
nPos = nPos + len(ab)
finalString = finalString + ab[nPos]
return finalString
def main():
print( "Caesar code".center(80, "="))
print("1. Encode your shit.")
print("2. Decode yo shizzle.")
inp = input(">")
if inp == "1":
sec = input("Enter secret number:\n\t")
encString = input("Enter a string to encode:\n\t")
print( "Your encoded string is %s" % encodeString(alphabet, encString, int(sec) ) )
elif inp == "2":
sec = input("Enter secret number:\n\t")
decString = input("Enter a string to decode:\n\t")
print( "Your decoded string is %s" % decodeString(alphabet, decString, int(sec) ) )
else:
sys.exit()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment