X Xerobit

ROT13 Encoder — Encode and Decode Text with ROT13

ROT13 shifts each letter 13 positions forward in the alphabet. It's its own inverse — applying ROT13 twice returns the original text. Here's how it works and where it's still used.

Mian Ali Khalid · · 4 min read
Use the tool
ROT13 / Caesar Cipher
Encode and decode ROT13 and arbitrary Caesar shifts. Letter frequency analysis. 100% client-side.
Open ROT13 / Caesar Cipher →

ROT13 (Rotate 13) shifts each alphabetic character 13 positions forward in the alphabet. A becomes N, B becomes O, and so on. After 13 shifts: N wraps back to A.

This self-inverse property — encoding and decoding use the same operation — is the defining characteristic of ROT13.

Use the ROT13 Cipher to encode and decode ROT13 instantly.

The ROT13 mapping

A ↔ N    B ↔ O    C ↔ P    D ↔ Q
E ↔ R    F ↔ S    G ↔ T    H ↔ U
I ↔ V    J ↔ W    K ↔ X    L ↔ Y
M ↔ Z

Lowercase letters map identically: a ↔ n, b ↔ o, etc.

Non-alphabetic characters (numbers, spaces, punctuation) are not modified.

Encoding examples

Input:   Hello, World!
ROT13:   Uryyb, Jbeyq!

Input:   The quick brown fox
ROT13:   Gur dhvpx oebja sbk

Input:   ROT13 encodes this
ROT13:   EBG13 rapbqrf guvf

ROT13 again:
ROT13:   ROT13 encodes this  ← Back to original

The second ROT13 of a ROT13-encoded string always returns the original. This is because 13 + 13 = 26 = alphabet length.

How to encode ROT13 in code

// JavaScript:
function rot13(text) {
  return text.replace(/[a-zA-Z]/g, char => {
    const code = char.charCodeAt(0);
    const base = code < 91 ? 65 : 97;  // 65=A, 97=a
    return String.fromCharCode(((code - base + 13) % 26) + base);
  });
}

console.log(rot13('Hello, World!'));  // "Uryyb, Jbeyq!"
console.log(rot13('Uryyb, Jbeyq!')); // "Hello, World!" (same function!)
# Python — built-in codecs:
import codecs
encoded = codecs.encode('Hello, World!', 'rot_13')
print(encoded)  # Uryyb, Jbeyq!

# Decode (same function):
decoded = codecs.encode(encoded, 'rot_13')
print(decoded)  # Hello, World!

# Manual implementation:
def rot13(text):
    result = []
    for char in text:
        if char.isalpha():
            base = ord('A') if char.isupper() else ord('a')
            result.append(chr((ord(char) - base + 13) % 26 + base))
        else:
            result.append(char)
    return ''.join(result)
# Command line:
echo "Hello, World!" | tr 'A-Za-z' 'N-ZA-Mn-za-m'
# Output: Uryyb, Jbeyq!

Where ROT13 is used

Spoiler protection (forums and communities)

The original use of ROT13. Forum posts hide spoilers for movies, books, and games:

"The twist ending is: [ROT13: gur zheqrere jnf gur qbpgbe nyy nybat]"

Readers who haven’t seen the movie see gibberish. Those who want the spoiler apply ROT13 to reveal it. Many forums have built-in ROT13 buttons.

Reddit used ROT13 spoiler tags for years before adopting native spoiler tags.

Bypassing basic content filters

Email spam filters and basic keyword filters can be evaded with ROT13. This is an adversarial use — legitimate for research or testing content filters, less legitimate for actual spam.

Joke encryption in documentation

Developer jokes and easter eggs often use ROT13:

// The password is: cnffjbeq123

Applying ROT13: password123. It’s humor, not security.

Puzzle design

ROT13 appears in Capture the Flag (CTF) security competitions as a trivial cipher challenge. It’s usually the first cipher beginners learn to recognize and crack.

ROT13 is not encryption

ROT13 offers zero security. It’s immediately recognizable (a 13-character shift Caesar cipher), requires no key, and anyone who knows about ROT13 can decode it instantly.

For any actual security need, use real encryption:

  • AES-256 for symmetric encryption
  • RSA or EC for asymmetric encryption

ROT13 is for obfuscation (preventing casual readers from seeing content), not protection.

ROT5, ROT18, ROT47

Variants of ROT13 for other character sets:

ROT5: Rotates digits 0–9 by 5. 0 ↔ 5, 1 ↔ 6, etc.

ROT18: ROT13 (letters) + ROT5 (digits) applied together.

ROT47: Rotates printable ASCII characters (code 33–126) by 47. Encodes letters, digits, AND punctuation:

"Hello, World!" → "w6==@[ (@C=5P"

ROT47 is less common but occasionally appears in CTF challenges.


Related posts

Related tool

ROT13 / Caesar Cipher

Encode and decode ROT13 and arbitrary Caesar shifts. Letter frequency analysis. 100% client-side.

Written by Mian Ali Khalid. Part of the Encoding & Crypto pillar.