Last active
August 29, 2015 13:56
-
-
Save myrkvi/8944556 to your computer and use it in GitHub Desktop.
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
# -*- 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