Encode, decode and crack Caesar ciphers
This tool shifts every letter of a text by the same number of places in the alphabet. Choose Encode to turn a message into cipher text, Decode to turn it back with a known shift, or Crack it when you do not know the shift. The output updates as you type, and the alphabet strip shows which cipher letter stands for each plain letter at the current shift. Upper and lower case are kept, and spaces, punctuation and accented letters pass through unchanged.
How the Caesar cipher works
Number the letters from A = 0 to Z = 25. To encode a letter with the key k, add k and keep the remainder after dividing by 26, so the count wraps around from Z back to A. To decode, subtract k instead:
cipher = (plain + k) mod 26
plain = (cipher − k) mod 26
Worked example: the word ZEBRA with a shift of 3.
| Plain letter | Number | + 3 | mod 26 | Cipher letter |
|---|---|---|---|---|
| Z | 25 | 28 | 2 | C |
| E | 4 | 7 | 7 | H |
| B | 1 | 4 | 4 | E |
| R | 17 | 20 | 20 | U |
| A | 0 | 3 | 3 | D |
So ZEBRA becomes CHEUD. The Z shows the wrap: 25 + 3 = 28, and 28 mod 26 = 2, which is C. Decoding CHEUD with a shift of 3 subtracts 3 from each number and gives ZEBRA again. A shift of 26 would bring every letter back to itself, which is why the useful keys run from 1 to 25. With Also shift digits on, the digits 0 to 9 move the same way modulo 10, so 9 + 3 = 12 becomes 2.
ROT13
ROT13 is the Caesar cipher with a shift of 13, half of 26. Shifting by 13 twice adds up to 26, a full turn of the alphabet, so encoding and decoding are the same step: A becomes N and N becomes A. Press ROT13 to set the shift, and the same button and the same mode both hide and reveal a text. In this tool, applying ROT13 twice always returns the original text.
Why the Caesar cipher is not secure
The whole secret of a Caesar cipher is one number from 1 to 25. Anyone can try all 25 and look for the one that reads as normal text, and a computer does that instantly. Crack it in this tool does exactly that. The cipher also keeps the pattern of the message: word lengths, spaces, doubled letters such as the EE in MEET and repeated words all show through. Use it for puzzles, escape rooms, geocaching clues and classroom exercises. To actually protect a message, use the text encryption tool, which encrypts with a password instead of a shift.
How Crack it finds the shift: frequency analysis
Letters in English are far from equally common. In Peter Norvig's count over the Google Books corpus, E makes up 12.49% of all letters, T 9.28% and A 8.04%, while J, Q and Z are each below 0.2%. The guide to letter frequency in English has the full table. A Caesar shift moves those frequencies along with the letters, so in a text encoded with a shift of 3, H turns up where E should be.
Crack it decodes the text with each of the 25 shifts and gives every result a chi-squared score. For each letter it compares the count it found with the count expected from English, squares the difference and divides by the expected count, then adds up all 26 terms. The lower the score, the more English-like the letters. Worked example, computed with this tool: the sentence "Meet me at the old bridge after sunset and bring the map with you." has 52 letters and a score of 12.9. Encoded with a shift of 3, the same text scores 354.8. When Crack it tries all shifts on the encoded text, the right one scores 12.9 and the next best, a shift of 15, scores 80.4.
The method needs enough English text. With a sentence or more, the right shift is usually first. Very short texts, and texts that are not English, can fail: the Latin "Veni, vidi, vici" with a shift of 3 has only 13 letters, and Crack it ranks the right shift seventh. That is why the tool shows all 25 results and lets you pick any of them.
Where the name comes from
The Roman writer Suetonius describes the cipher in his Life of Julius Caesar (chapter 56). According to the 1913 Loeb translation on the University of Chicago's LacusCurtius site, Caesar wrote confidential matters in his letters in cipher, and to read them one had to "substitute the fourth letter of the alphabet, namely D, for A". That is a shift of 3, the default in this tool.
How to use the Caesar cipher tool
- 1Choose Encode, Decode or Crack it.
- 2Set the shift with the slider or the number box, or press ROT13. Switch on Also shift digits if numbers should change too.
- 3Type or paste your text. The result appears as you type.
- 4In Crack it, read the ranked list and press Use on the line that makes sense.
- 5Copy the result, or use it as the new input to check the round trip.
Sources
- Peter Norvig, English Letter Frequency Counts: Mayzner Revisited: the 26 letter frequencies used for the chi-squared score, counted over 3,563,505,777,820 letters from Google Books
- Suetonius, Life of Julius Caesar, chapter 56, Loeb Classical Library 1913, on LacusCurtius (University of Chicago)
Related guides
- Hashing vs Encryption vs Encoding: What Each One Does
- UTF-8 and Unicode Explained: Code Points, Bytes and Mojibake
- How Long Should a Password Be? What NIST Recommends
Frequently asked questions
What is the Caesar cipher?
A cipher that replaces every letter with the letter a fixed number of places further along the alphabet, wrapping around from Z to A. With a shift of 3, A becomes D, B becomes E and Z becomes C. To decode, you shift back by the same number.
What is ROT13?
ROT13 is the Caesar cipher with a shift of 13. Because the alphabet has 26 letters, shifting by 13 twice brings every letter back to where it started, so the same step both encodes and decodes. Press the ROT13 button to set the shift to 13.
How do I decode a Caesar cipher without the key?
Paste the text and choose Crack it. The tool tries all 25 shifts and ranks the results by how close their letter frequencies are to English. For a sentence or more of English, the right shift is usually at the top. Short texts and texts in other languages can rank the wrong shift first, so read the list.
What happens to numbers, spaces and punctuation?
They stay as they are, and so do accented letters such as é or ü. Only the 26 letters A to Z are shifted, and upper and lower case are kept. Switch on Also shift digits to move 0 to 9 by the same amount, counted modulo 10, so with a shift of 3 the digit 9 becomes 2.
Is the Caesar cipher safe for passwords or private messages?
No. There are only 25 possible shifts, and a computer tries them all in a fraction of a second, as Crack it shows. Use it for puzzles, games and teaching. For real protection, use encryption with a strong password, such as the text encryption tool on this site.
Is my text sent anywhere?
No. Encoding, decoding and cracking all run in your browser. Copy link shares only the mode, the shift and the digit setting, never your text.