Created
January 7, 2014 01:32
-
-
Save vanzaj/8293295 to your computer and use it in GitHub Desktop.
poor man crypto
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
# poor man crypto | |
import base64 | |
def _shiftchars(s): | |
lens = len(s) | |
if lens == 1: | |
return s | |
elif lens == 2: | |
return s[1]+s[0] | |
else: | |
return s[-1]+s[1:-1]+s[0] | |
def encode(msg, scramble=True): | |
enc = base64.urlsafe_b64encode(msg) | |
enc = enc.encode('rot13')[::-1] | |
if scramble: | |
enc = _shiftchars(enc) | |
return enc | |
def decode(msg, scramble=True): | |
if scramble: | |
dec = _shiftchars(msg) | |
else: | |
dec = msg | |
dec = base64.urlsafe_b64decode(dec[::-1].encode('rot13')) | |
return dec |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment