Skip to content

Instantly share code, notes, and snippets.

@stevekrenzel
Created May 1, 2012 07:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevekrenzel/ccda26ce1df4e72c1d53 to your computer and use it in GitHub Desktop.
Save stevekrenzel/ccda26ce1df4e72c1d53 to your computer and use it in GitHub Desktop.
ROT-13
>>> from string import ascii_lowercase, ascii_uppercase, maketrans, translate
>>> target = ascii_lowercase[13:] + ascii_lowercase[:13] + ascii_uppercase[13:] + ascii_uppercase[:13]
>>> tr = maketrans(ascii_lowercase + ascii_uppercase, target)
>>> translate("This is a message", tr)
'Guvf vf n zrffntr'
>>> "This is a message.".encode('rot13')
'Guvf vf n zrffntr.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment