Skip to content

Instantly share code, notes, and snippets.

@akkefa
Created June 10, 2018 16:00
Show Gist options
  • Save akkefa/e87b6d8d94ba20c63007123c8e801c74 to your computer and use it in GitHub Desktop.
Save akkefa/e87b6d8d94ba20c63007123c8e801c74 to your computer and use it in GitHub Desktop.
Rot13 is a cipher: it rotates characters forward 13 places. This makes text unreadable. But as a cipher, it is reversible by applying the translation a second time. We write rot13 with maketrans and translate.
# Create translation table.
trans = str.maketrans("abcdefghijklmnopqrstuvwxyz",
"nopqrstuvwxyzabcdefghijklm")
# Apply rot13 translation.
print("gandalf".translate(trans))
print("gandalf".translate(trans).translate(trans))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment