Last active
October 7, 2015 11:17
-
-
Save simonhayward/3156361 to your computer and use it in GitHub Desktop.
Rot*
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
from string import ascii_uppercase as uc, ascii_lowercase as lc, maketrans | |
def rot_func(text, encode=True, rotate=13): | |
letters = uc + lc | |
rot = "".join((x[:rotate][::-1] + x[rotate:][::-1])[::-1] for x in (uc,lc)) | |
src, trg = (letters, rot) if encode else (rot, letters) | |
trans = maketrans(src, trg) | |
return text.translate(trans) | |
text = "Text to ROT" | |
encoded = rot_func(text) | |
decoded = rot_func(encoded, encode=False) | |
print(""" | |
Text:\t{text} | |
Encode:\t{encoded} | |
Decode:\t{decoded} | |
""".format(**locals())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For python 2.x if you wanted a different rotate than 13 - str.encode("rot13")