Skip to content

Instantly share code, notes, and snippets.

@4383
Last active November 23, 2020 14:57
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 4383/3713d90485102154c165b19a6601e936 to your computer and use it in GitHub Desktop.
Save 4383/3713d90485102154c165b19a6601e936 to your computer and use it in GitHub Desktop.
Python ROT13 converter / deconverter
import string #fixed typo was using
text = str(input('tip your text to convert: ', ))
rot13 = string.maketrans(
"ABCDEFGHIJKLMabcdefghijklmNOPQRSTUVWXYZnopqrstuvwxyz",
"NOPQRSTUVWXYZnopqrstuvwxyzABCDEFGHIJKLMabcdefghijklm")
string.translate(text, rot13)
# Example
# 'Hello World!
# 'Uryyb Jbeyq!
@Michael-Schulze
Copy link

Michael-Schulze commented Nov 20, 2020

Just a comment, this code example above is for Python2.

In Python 3 there is no need (not possible) to import string with maketrans.
There the code could look like this:

text = str(input('tip your text to convert: ', ))
normalAlpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
rot13Alpha = "NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm"
text.translate(str.maketrans(normalAlpha,rot13Alpha))

@4383
Copy link
Author

4383 commented Nov 20, 2020

@Michael-Schulze thanks for the heads-up.

Indeed this is an old gist not really updated since its creation and surely only compatible with python2.

I'll try to update it soon with your advices.

Thanks

@Michael-Schulze
Copy link

Hi,

yes I know. I was searching for a similar thing and found your code and struggled a little bit with it. So I decided to give a comment, how to get it working.

@4383
Copy link
Author

4383 commented Nov 23, 2020

@Michael-Schulze Much appreciated, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment