Skip to content

Instantly share code, notes, and snippets.

@gvx
Created November 16, 2008 08:04
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 gvx/25431 to your computer and use it in GitHub Desktop.
Save gvx/25431 to your computer and use it in GitHub Desktop.
A ROT13 function for Pyton.
#By Robin Wellner (gvx)
#I hereby waive copyright and related or neighboring rights to this work
#See the Creative Commons Zero Waiver at <http://creativecommons.org/publicdomain/zero/1.0/>
def rotn(intext, n):
outtext = []
for char in intext:
if 65 <= ord(char) < (65+26):
char = chr(((ord(char) - 65) +n) % 26 + 65)
elif 97 <= ord(char) < (97+26):
char = chr(((ord(char) - 97) +n) % 26 + 97)
outtext.append(char)
return ''.join(outtext)
def rot13(intext):
return rotn(intext, 13)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment