How do I do a Rot13?

Tim Peters tim.one at comcast.net
Sun Oct 27 17:50:32 EST 2002


]John Draper]
> How do I write a function to do a "rot13" to a string?
> Do I have to do this character-by-character or is there a translate
> function which will do this for me?

In a recent-enough Python, rot13 is a std codec:

>>> 'abc'.encode('rot13')
'nop'
>>> 'nop'.encode('rot13')
'abc'
>>>

If that doesn't work for you, see the docs for string.translate().






More information about the Python-list mailing list