Skip to content

Instantly share code, notes, and snippets.

@en0
Last active December 23, 2015 01:09
Show Gist options
  • Save en0/6558972 to your computer and use it in GitHub Desktop.
Save en0/6558972 to your computer and use it in GitHub Desktop.
A simple rot13 implementation.
"""Apply Rot13 cipher to argument list"""
import string
import sys
def rot13(text):
"""Apply the rot13 cipher to the given text
Args:
text: The text to be shifted.
Returns:
The content of `text` shifted by 13 chars.
"""
map = ["abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
"nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM"]
# Add non shifted chars to the conversion map.
map[0] += string.digits + string.punctuation + string.whitespace
map[1] += string.digits + string.punctuation + string.whitespace
# This is probably not very pythonic but it remaps the chars.
return "".join([map[1][x] for x in (map[0].find(s) for s in text)])
if __name__ == "__main__":
if len(sys.argv) < 2:
raise SyntaxError("Missing parameters.")
print(rot13(" ".join(sys.argv[1:])))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment