What Are ROT13 and the Caesar Cipher? Worked Example, Cracking Method and Limits
Updated: November 6, 2026 · AracMerkezi
▶ Open ROT13 and Caesar Cipher
The Caesar cipher is one of the oldest known encryption methods. It shifts every letter forward in the alphabet by a fixed number of places so the text becomes unreadable. ROT13 is the special case that shifts by 13 letters. Today it is used not for real security but for puzzles, teaching and fun. This guide shows how to apply the method by hand and in code, what changes with the Turkish alphabet, and why the cipher can be broken in a few minutes.
How does the Caesar cipher work?
You pick a key (the shift). Every letter moves forward by that many places in the alphabet. When you pass the end of the alphabet you wrap around to the start. If you number the letters A=0, B=1, C=2 ... Z=25, the rule is one line:
Cipher index = (plain index + key) mod 26, and to decrypt, plain index = (cipher index − key) mod 26.
“mod 26” describes the wrap-around: with key 3, X, Y, Z become A, B, C, because for Y we get (24 + 3) = 27 and 27 − 26 = 1, which is B.
Step-by-step example: MERHABA, key 3
The table below shows how each letter changes (26-letter Latin alphabet):
| Plain letter | Index | Index + 3 | Cipher letter |
|---|---|---|---|
| M | 12 | 15 | P |
| E | 4 | 7 | H |
| R | 17 | 20 | U |
| H | 7 | 10 | K |
| A | 0 | 3 | D |
| B | 1 | 4 | E |
| A | 0 | 3 | D |
The result is PHUKDED. To decrypt, subtract the same number: P (15) − 3 = 12 = M, and so on. The most common mistake when working by hand is forgetting to wrap around near the end of the alphabet, so test with letters such as Z, Y and X separately.
What is ROT13?
ROT13 is the Caesar cipher with a shift of 13. Because the Latin alphabet has 26 letters, 13 is exactly half of it; since 13 + 13 = 26, applying the same operation twice returns the original text. Encrypting and decrypting are the same operation. Example: MERHABA → ZREUNON → ROT13 again → MERHABA. Only the letters A–Z change; digits, spaces and Turkish letters such as ü and ö stay as they are: “Merhaba Dünya” → “Zreunon Qüaln”.
ROT13 was used on internet forums to hide a puzzle’s answer or “spoiler” so readers would not see it by accident. We tried the following one-line methods and all of them gave the same result:
- Python:
import codecs; codecs.encode('MERHABA', 'rot13')returnsZREUNON. - Linux/macOS terminal:
echo Merhaba | tr 'A-Za-z' 'N-ZA-Mn-za-m'returnsZreunon. - JavaScript: the expression
s.replace(/[a-z]/gi, c => String.fromCharCode((c.charCodeAt(0) - (c <= 'Z' ? 65 : 97) + 13) % 26 + (c <= 'Z' ? 65 : 97)))produces “Zreunon” for “Merhaba”.
Caesar with the Turkish alphabet: 29 letters
The Turkish alphabet has 29 letters (including Ç, Ğ, İ, Ö, Ş, Ü; there is no q, w or x). Classic ROT13 and most tools use the 26-letter Latin alphabet and leave the special letters unchanged. A Caesar shift on the Turkish alphabet (A B C Ç D E F G Ğ H I İ J K L M N O Ö P R S Ş T U Ü V Y Z) gives different output: MERHABA with key 3 becomes ÖĞTJÇDÇ, because three places after M is Ö. The modulus here is 29; since 29 is odd there is no “half alphabet”, and applying a shift of 13 twice does not restore the text (MERHABA → ZÖDŞKLK → JCOFVYV). If you are preparing a puzzle, make sure the solver uses the same alphabet and the same rule. The tool on our site offers both a 26-letter and a 29-letter alphabet.
How do you break a Caesar cipher?
Method 1: brute force. In a 26-letter alphabet there are 25 meaningful keys; you try the 25 shifts in order and pick the one that yields a meaningful word. For “PHUKDED”, the first three attempts:
| Attempt (shift back) | Resulting text |
|---|---|
| 1 | OGTJCDC |
| 2 | NFSIBCB |
| 3 | MERHABA |
The third row produced a readable word, so the key is 3. Even by hand, 25 attempts take a few minutes; for a computer it is a fraction of a second.
Method 2: frequency analysis. If the plain text is Turkish, the letters A and E appear very often. Example: encrypting the sentence “BUGUN AKSAM SAAT ALTIDA ANKARADA BULUSALIM” with key 5 gives “GZLZS FPXFR XFFY FQYNIF FSPFWFIF GZQZXFQNR”. The most frequent letter in the cipher text is F (11 times). If we assume the most frequent plain letter is A, the shift is F − A = 5; shifting the text back by 5 makes the sentence readable. With short texts this guess can be wrong; with long texts it is reliable.
Why is it not secure?
- The number of keys is tiny: a 26-letter alphabet has only 25 different shifts. For comparison, the key space of a modern algorithm such as AES-128 is roughly 3.4 × 10^38.
- Letter frequencies do not change; every letter always maps to the same letter, so language statistics show through.
- Word spaces and lengths are preserved, which makes guessing easier.
So do not use the Caesar cipher for passwords, personal data or secret information. Real security needs current, audited encryption libraries. For password generation, see the secure password guide.
Difference from Base64 and Base32
The Caesar cipher shifts letters, whereas Base64 and Base32 merely encode data with a different character set. None of them provides security without a key:
- Base64: Represents every 3 bytes of data with 4 characters; used for email attachments, binary data inside JSON and data URIs.
- Base32: Uses the characters A–Z and 2–7; it is resistant to upper/lower-case confusion. For details, see the Base32 vs Base64 guide.
- Caesar/ROT13: Only shifts letters, so it is for fun only.
Common mistakes
- Mistaking ROT13 for “encryption” and sharing secrets with it.
- Using key 26 (or 29): after a full turn the text does not change at all.
- Encrypting Turkish text with a 26-letter tool while the recipient decrypts with a 29-letter tool; the results will not match.
- Breaking the upper/lower-case distinction; a good tool keeps capitals capital and lowercase lowercase.
- Trying only one direction (forward) when cracking; decryption is a shift backward.
Glossary
- Plain text: The original, unencrypted writing.
- Cipher text: The unreadable text that results after shifting.
- Key: The number that determines how many letters to shift.
- Brute force: Trying every possible key in turn.
- Frequency analysis: Guessing the key by looking at letter counts.
Quick try
With the ROT13 and Caesar Cipher tool you can encrypt and decrypt your text with any shift you like. For encoding, see the Base64 Encode/Decode and Base32 Encode/Decode tools. If you are curious about the difference from hashing, read the guide What Is a Hash?. This article is for educational purposes; consult expert sources for security decisions.
Frequently asked questions
Why does ROT13 return to the original text when applied twice?
The Latin alphabet has 26 letters and 13 is exactly half; two shifts of 13 make 26, so you return to the starting point. The 29-letter Turkish alphabet does not have this property.
Is the Caesar cipher secure?
No; a 26-letter alphabet has only 25 possible shifts and letter frequency does not change, so it can be broken quickly even by hand.
Is Base64 encryption?
No; Base64 is only an encoding format and has no key, so it provides no security.
Tools mentioned in this guide
More guides
- What Is Base32? Base32 vs Base64, Step-by-Step Encoding and TOTP Keys – How does Base32 work? Encode 'foo' to MZXW6=== bit by bit, compare sizes with Base64 and hex, and see why two-factor secrets are shown in Base32.
- How to Create a Secure Password: Length, Entropy and 8 Rules – How to create a secure password: password strength in bits, random-word passphrases, command-line generation and eight practical rules.
- What Are JSON, Base64 and URL Encoding? Encoding vs Encryption vs Hashing – What do JSON, Base64, URL encoding, HTML entities, SHA and JWT do? Encoding vs encryption vs hashing, with examples that were run and verified.
- How to Convert HEX to RGB Color Codes: Step-by-Step Examples – How to convert a HEX color code to RGB and back: hexadecimal basics, short and 8-digit HEX, darkening math and verified JavaScript and Python snippets.
- What Is a JWT (JSON Web Token) and How Does It Work? Decoding, Signature and Security – What is a JWT, how do you decode it and verify its signature? A real sample token, exp time math, a tampering test and security mistakes.
This article is for general information only and is not legal, financial or medical advice. We are not an official institution.