Caesar cipher calculator
Encode or decode with a shift, ROT13 or a Vigenère key, or try all 25 shifts at once.
The Caesar cipher is the oldest and simplest substitution cipher: move every letter a fixed number of places along the alphabet. This page does it in both directions, adds ROT13 and the Vigenère cipher with a key, and can try every shift on a mystery message. It is a classroom, puzzle and escape-room tool, and the text below explains honestly what these ciphers can and cannot do.
What is the Caesar cipher?
The Caesar cipher replaces every letter with the letter a fixed number of places further along the alphabet. With a shift of 3, A becomes D, B becomes E and Z wraps around to C, so ATTACK AT DAWN becomes DWWDFN DW GDZQ. Decoding is the same move in the opposite direction. The Roman historian Suetonius describes Julius Caesar writing secret messages this way, with the fourth letter D standing for A, in his life of Caesar (Divus Iulius, chapter 56).
How do I decode a Caesar cipher when I don't know the shift?
Use the brute-force tab. There are only 25 useful shifts (a shift of 26 returns the original text), so the page prints all 25 decodings and you pick the one that reads as English. For the ciphertext EXXEGOEXSRGI, shift 4 gives “ATTACKATONCE”. The page also marks the decoding whose letter frequencies are closest to English with a star, which works well on a sentence or more and is unreliable on a few letters.
What is ROT13?
ROT13 is the Caesar cipher with a shift of 13. Because the alphabet has 26 letters, applying it twice gives back the original text, so one operation both encodes and decodes: Hello, World! becomes Uryyb, Jbeyq!. It is used to hide spoilers and punchlines from a casual glance, never as encryption, since anyone can undo it with the same function.
How does the Vigenère cipher work?
Instead of one shift, the Vigenère cipher uses a keyword and shifts each letter by the corresponding keyword letter (A = 0, B = 1, … Z = 25), repeating the key along the text. With the key LEMON, ATTACKATDAWN becomes LXFOPVEFRNHR: A + L = L, T + E = X, T + M = F, A + O = O, C + N = P, then the key starts over with L. The same plaintext letter can therefore turn into different ciphertext letters, which hides the letter frequencies that give away a simple Caesar shift. This page advances the key only on letters, not on spaces or punctuation.
Is the Caesar cipher secure?
No. It has only 25 possible keys, so a person can try them all in a minute and a computer in a blink; frequency analysis is faster still, and the earliest surviving descriptions of it date to the work of the 9th-century scholar Al-Kindi. The Vigenère cipher resisted for centuries and was nicknamed le chiffre indéchiffrable, but Friedrich Kasiski published a general method of breaking it in 1863, and William Friedman's index of coincidence (1920s) estimates the key length. Treat both as puzzles and teaching tools. For anything that really needs protection, use modern, publicly reviewed encryption in an established program.
Does it keep upper and lower case, spaces and punctuation?
Yes. Only the letters A to Z are shifted, upper case stays upper case and lower case stays lower case, and digits, spaces, punctuation and letters with accents are left exactly as typed. A shift can be negative or larger than 26: a shift of −3 is the same as 23, and 29 is the same as 3.
Who invented the Vigenère cipher?
Despite the name, the keyword scheme was first described by Giovan Battista Bellaso in 1553. Blaise de Vigenère published a different, stronger autokey cipher in 1586, and the later cipher was wrongly credited to him. Charles Babbage appears to have broken it before Kasiski but did not publish his work.
The method with every variable
Number the letters A = 0, B = 1, … Z = 25. For a shift k the encoded letter is (p + k) mod 26, where p is the number of the plain letter, and decoding is (c − k) mod 26 where c is the cipher letter. The remainder after dividing by 26 is what makes Z wrap around to A. For the Vigenère cipher the shift k changes from letter to letter: it is the number of the current key letter, so the encoded letter is (p + ki) mod 26 with i counting through the key and starting over at its end. A one-letter key makes it a Caesar cipher again.
Worked example
Encode ATTACK AT DAWN with a shift of 3: A→D, T→W, T→W, A→D, C→F, K→N, then A→D and T→W, and D→G, A→D, W→Z, N→Q, giving DWWDFN DW GDZQ. Decoding it with the same shift returns ATTACK AT DAWN. For the Vigenère cipher, ATTACKATDAWN with the key LEMON gives LXFOPVEFRNHR. To crack a message without a key, try all shifts: the ciphertext EXXEGOEXSRGI decodes to ATTACKATONCE at shift 4, and the other 24 lines are gibberish.
Why frequency analysis works, and its limits
In ordinary English the letter E makes up about 12.7% of the letters, T about 9.1%, A about 8.2% and Z only about 0.074% (Lewand, 2000). A Caesar shift moves these shares but does not change them, so the most common letter in a long ciphertext is probably the shifted E, and the distance from E to that letter is the shift. The brute-force tab compares the letter counts of each of the 25 decodings with the English table using a chi-squared score and stars the best one. This is our own heuristic, not a standard from the literature, and it needs at least about a dozen letters; a short word can fit several shifts equally well.
Common mistakes
- Shifting in the wrong direction. Encoding with +3 and decoding with +3 gives a different text; decode with −3 (or choose Decode). In puzzles that give only a number, try both directions.
- Counting the key through spaces. Different tools advance the Vigenère key differently. Here it moves only on letters, which is the most common convention; if an answer from another tool differs, compare how that tool treats spaces and punctuation.
- Forgetting that the alphabet is English. Only A–Z are shifted. A letter such as é or ß is left alone, and a ciphertext made for a 29- or 33-letter alphabet cannot be solved with this 26-letter shift.
- Using these ciphers for secrets. They protect nothing against anyone who tries. Do not rely on ROT13, Caesar or Vigenère for passwords, personal data or anything that matters.
Sources: Suetonius, Divus Iulius 56 (Caesar's shift of three; cited via the Wikipedia article “Caesar cipher”, the chapter itself was not opened); Wikipedia, “Vigenère cipher” (Bellaso 1553, Vigenère 1586, Kasiski 1863, Friedman 1920s); R. Lewand, Cryptological Mathematics (Mathematical Association of America, 2000), p. 36, letter frequencies as listed in Wikipedia “Letter frequency”. Related: Morse code translator, base converter, modulo calculator, password entropy calculator, Roman numeral converter and check digit calculator.