The idea
ROT13 stands for rotate by 13 places. Every letter is replaced by the letter 13 positions further along the alphabet, wrapping around at the end. It is a special case of the Caesar cipher, which can use any shift from 1 to 25.
A worked example
H e l l o W o r l d
U r y y b J b e y qH moves to U, e to r, l to y, o to b, W to J, r to e and d to q. Only letters change. Spaces, digits and punctuation stay as they are.
Why it is reversible
With 26 letters, a shift of 13 is exactly half a turn. Doing it twice is a full turn, so ROT13 is its own inverse. That makes it unusually simple to use, because the same step encodes and decodes.
Where it is used
ROT13 became popular on early online discussion groups, where people used it to hide spoilers, punchlines and offensive jokes so that readers had to choose to reveal them. Today it still appears in puzzles, geocaching hints and simple programming exercises.
Not a secret code
ROT13 offers no real protection. There is no key, and anyone who knows the trick can read it. Never use it for passwords or sensitive data. For real protection, use proper encryption.
ROT13 in code
# Python
import codecs
print(codecs.encode("Hello, World!", "rot_13"))
// PHP
echo str_rot13("Hello, World!");
# Linux and macOS terminal
echo "Hello, World!" | tr 'A-Za-z' 'N-ZA-Mn-za-m'Related schemes
- ROT5: rotates the digits 0 to 9 by 5.
- ROT18: ROT13 for letters plus ROT5 for digits.
- ROT47: rotates the printable ASCII characters from ! to ~ by 47.
Try it in the ROT13 encoder, decode with the ROT13 decoder, or convert whole files with the batch converter.
Try it. Encode or decode any text with ROT13 in your browser.