Skip to content

Instantly share code, notes, and snippets.

@gpiancastelli
Created February 1, 2011 22:30
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 gpiancastelli/806851 to your computer and use it in GitHub Desktop.
Save gpiancastelli/806851 to your computer and use it in GitHub Desktop.
A basic ROT13 implementation in Python
#!/usr/bin/env python2.6
import sys
from os.path import basename
from string import lowercase, uppercase, maketrans
if len(sys.argv) != 2:
print 'Usage: %s text' % basename(sys.argv[0])
sys.exit(1)
ROT = 13
rotated = [letters[ROT:] + letters[:ROT] for letters in (lowercase, uppercase)]
table = maketrans(lowercase + uppercase, ''.join(rotated))
print sys.argv[1].translate(table)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment