Python: Rot13 text transformationΒΆ

If GPG isn’t enough, you can use ROT13 for your encryption needs! ;)

def rotate_string(s, r=0):
    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'))
            c2 = c
        s2 += c2
    return s2

Download source from github gist

comments powered by Disqus

Previous topic

Python: PyQt4 Snippets

Next topic

Python: scale conversion

This Page