cipher.ink Write a message

Ciphers · Classical ciphers

ROT13

ROT13 is a Caesar shift of 13, so applying it twice gets your text back. It hides spoilers, never secrets.

ROT13 ("rotate by 13 places") is the Caesar cipher with the shift fixed at 13. Since 13 is exactly half of 26, running text through it a second time brings back the original, so one operation both encodes and decodes. It protects nothing. Its job is to keep a punchline, a spoiler or a puzzle answer from jumping out at someone who isn't ready for it.

Try it

Nothing you type here leaves your browser.

Paste the result back in and you get the starting text. There's no key to set and no Decrypt button, which is the whole idea.

Why 13 is special

Fold the alphabet in half and you get two rows of 13. ROT13 swaps each letter with the one directly above or below it: A with N, B with O, M with Z.

ROT13: every letter trades places with its partnerABCDEFGHIJKLMNOPQRSTUVWXYZ
ROT13 is a swap between two halves of the alphabet. Swapping twice puts every letter back.

A swap is its own inverse, so a ROT13 program needs no separate decode routine. On Unix, one command does the job: tr 'A-Za-z' 'N-ZA-Mn-za-m'. Case survives, and digits, spaces and punctuation pass through untouched, so Why did the chicken cross the road? becomes Jul qvq gur puvpxra pebff gur ebnq?.

Any other shift needs a decode step, because it moves the letters one way and you have to move them back. Shift by 3 and then by 3 again and you've shifted by 6, not zero. Only a shift of half the alphabet undoes itself, and only when the alphabet has an even number of letters.

Cousins: ROT5, ROT18 and ROT47

People have stretched the idea to other character sets, each time picking a shift that's half the set.

NameWhat it rotatesShiftExample: Hello, World! 2026
ROT13The 26 letters13Uryyb, Jbeyq! 2026
ROT5The 10 digits5Hello, World! 7571
ROT18Letters by 13 and digits by 513 and 5Uryyb, Jbeyq! 7571
ROT47The 94 printable ASCII characters, ! to ~47w6==@[ (@C=5P a_ae

ROT47 scrambles punctuation too, so its output looks less like text, but it's no harder to undo. The snippet further down includes it.

Where ROT13 turned up

Online discussion groups took up ROT13 in the early 1980s. Usenet readers wanted a way to post a joke that might offend, or the answer to a puzzle, so that anybody reading the message had to choose to decode it. Many newsreaders offered a one-key "decode ROT13" command, and the habit stuck. It's still the usual way to hide spoilers on puzzle forums and geocaching hints.

It has also appeared where it doesn't belong. Windows records which programs you launch under the "UserAssist" registry keys and stores the program names in ROT13. That's obfuscation, not secrecy, and forensic tools reverse it in one line.

A few English words even turn into other English words. In the word list that ships with macOS, nowhere becomes abjurer and the other way round, and clerk pairs with pyrex. The ROT13 of "Uryyb" is "Hello". That's as close to magic as the cipher gets.

Why there's nothing to break

Every other cipher on this site has a key, and breaking it means finding the key. ROT13 has none. Anyone who knows the method, and the method is the name, can decode any message at once. That's why cryptographers use it as the standing joke about bad security: "double ROT13" encryption is the same as no encryption, because applying it twice is the identity. A product that claims to encrypt your data with ROT13 or a close relative isn't encrypting it.

If you need to keep something secret, and not merely out of sight, use a cipher with a real key. cipher.ink seals your message in your browser with AES-256 before it leaves, and the key never reaches the server.

The code

ROT13 for letters and ROT47 for the printable ASCII range.

// ROT13 is a Caesar shift of 13. Half of 26, so doing it twice gives back the original.
function rot13(text) {
  return text.replace(/[a-z]/gi, function (ch) {
    var base = ch <= 'Z' ? 65 : 97;
    return String.fromCharCode((ch.charCodeAt(0) - base + 13) % 26 + base);
  });
}

// ROT47 does the same over the 94 printable ASCII characters from '!' to '~', shifting by 47.
function rot47(text) {
  return text.replace(/[!-~]/g, function (ch) {
    return String.fromCharCode(33 + (ch.charCodeAt(0) - 33 + 47) % 94);
  });
}

The first function is the Caesar cipher with the shift hard-coded to 13. The second applies the same idea to 94 characters with a shift of 47. Neither needs an "undo" function.

ROT13 is one point on the Caesar family. Move the shift and you have the Caesar cipher. Reverse the whole alphabet and you have Atbash, which is also its own inverse. Stack several shifts keyed by a word and you get the Vigenère cipher. For a shift of unknown size, the all-purpose decoder is the Caesar cipher tool.

Common questions

Is ROT13 encryption?

No. Encryption needs a secret key, and ROT13 has none, so anyone who knows the name can undo it. Its job is to stop the eye catching a spoiler, not to stop a person reading it. If you need to keep a secret, see how cipher.ink seals a message with a real key.

Why 13 and not some other number?

Because 26 letters split into two halves of 13. A shift of 13 sends each letter to its partner in the other half, and the partner's partner is the original, so one function does both jobs. A shift of 12 or 14 would need a separate decode step.

What does ROT13 do to numbers and punctuation?

Nothing. Only the 26 letters rotate, and digits, spaces and symbols pass through. ROT5 rotates the digits by 5, ROT18 handles letters and digits together, and ROT47 covers all 94 printable ASCII characters.

How do I do ROT13 on the command line?

On Linux and macOS, echo 'Hello' | tr 'A-Za-z' 'N-ZA-Mn-za-m' prints Uryyb. The same command decodes it.

Does ROT13 work on other alphabets?

ROT13 itself covers only the 26-letter Latin alphabet. An alphabet with an even number of letters has its own half-way rotation (11 places for the 22 letters of Hebrew, for example), while an alphabet with an odd number of letters has no rotation that undoes itself.

Further reading

  1. Jargon File: ROT13
  2. Wikipedia: ROT13
  3. Didier Stevens: UserAssist keys and ROT13