Skip to content

Instantly share code, notes, and snippets.

@rshk
Created December 19, 2012 17:06
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 rshk/4338365 to your computer and use it in GitHub Desktop.
Save rshk/4338365 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import sys
try:
text = sys.argv[1]
except:
print "Usage: rot13 <text>"
sys.exit(1)
def rotate_string(s, r=0):
s2=""
for c in s:
if c >= 'a' and c <= 'z':
c2 = chr(((ord(c)-ord('a')) + r) % 26 + ord('a'))
elif c >= 'A' and c <= 'Z':
c2 = chr(((ord(c)-ord('A')) + r) % 26 + ord('A'))
else:
c2 = c
s2 += c2
return s2
for i in range(26):
print "%d:" % i, rotate_string(text, i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment