Caesar Cipher
Encode, decode or try every Caesar shift. Choose 1–25, use shift 13 for ROT13, or select Brute Force Decoder.
Caesar cipher brute force: the short answer
A Caesar cipher has just 25 non-trivial keys. Trying all of them is effectively instant for a short message: decrypt with each shift from 1 to 25, then look for familiar words, sensible grammar and a coherent meaning. A low English-frequency score can point you to a candidate, but reading the whole result is the final check. Shift 0 would simply repeat the input.
Not sure it is Caesar? Try the cipher identifier.
Updated .
Worked example: rank every Caesar shift
Our plaintext is the public-domain opening sentence of Jane Austen's Pride and Prejudice (1813), chapter I, from Project Gutenberg's text. We join the source line break with a space and encrypt with shift 7, keeping case, spaces and punctuation. There are 92 A–Z letters to score.
It is a truth universally acknowledged, that a single man in possession of a good fortune must be in want of a wife.
Ciphertext to paste into the tool:
Pa pz h aybao bupclyzhssf hjruvdslknlk, aoha h zpunsl thu pu wvzzlzzpvu vm h nvvk mvyabul tbza il pu dhua vm h dpml.Example computed 2026-10-29 with this page's codec.
The table scores the entire decrypted sentence, displaying only its first 40 characters. It sorts by the unrounded chi-squared score, lowest first; ties use the smaller shift. A listed shift is the encryption key being undone (subtract it to decrypt).
| Rank | Shift | χ² score | First 40 characters |
|---|---|---|---|
| 1 | 7 | 14.029 | It is a truth universally acknowledged, |
| 2 | 20 | 355.827 | Vg vf n gehgu havirefnyyl npxabjyrqtrq, |
| 3 | 19 | 374.539 | Wh wg o hfihv ibwjsfgozzm oqybckzsrusr, |
| 4 | 15 | 416.708 | Al ak s ljmlz mfanwjksddq sucfgodwvywv, |
| 5 | 13 | 473.558 | Cn cm u nlonb ohcpylmuffs uwehiqfyxayx, |
| 6 | 6 | 644.287 | Ju jt b usvui vojwfstbmmz bdlopxmfehfe, |
| 7 | 18 | 662.072 | Xi xh p igjiw jcxktghpaan przcdlatsvts, |
| 8 | 3 | 679.237 | Mx mw e xvyxl yrmzivweppc egorsapihkih, |
| 9 | 14 | 702.370 | Bm bl t mknma ngboxklteer tvdghpexwzxw, |
| 10 | 9 | 810.106 | Gr gq y rpsrf slgtcpqyjjw yailmujcbecb, |
| 11 | 5 | 848.504 | Kv ku c vtwvj wpkxgtucnna cempqyngfigf, |
| 12 | 23 | 848.518 | Sd sc k dbedr exsfobckvvi kmuxygvonqon, |
| 13 | 25 | 872.139 | Qb qa i bzcbp cvqdmzaittg iksvwetmloml, |
| 14 | 11 | 955.645 | Ep eo w pnqpd qjeranowhhu wygjkshazcaz, |
| 15 | 24 | 1124.511 | Rc rb j cadcq dwrenabjuuh jltwxfunmpnm, |
| 16 | 4 | 1137.007 | Lw lv d wuxwk xqlyhuvdoob dfnqrzohgjhg, |
| 17 | 22 | 1188.967 | Te td l ecfes fytgpcdlwwj lnvyzhwporpo, |
| 18 | 1 | 1218.976 | Oz oy g zxazn atobkxygrre giqtucrkjmkj, |
| 19 | 17 | 1268.781 | Yj yi q jhkjx kdyluhiqbbo qsadembutwut, |
| 20 | 2 | 1337.129 | Ny nx f ywzym zsnajwxfqqd fhpstbqjilji, |
| 21 | 8 | 1341.269 | Hs hr z sqtsg tmhudqrzkkx zbjmnvkdcfdc, |
| 22 | 10 | 1385.385 | Fq fp x qorqe rkfsbopxiiv xzhkltibadba, |
| 23 | 12 | 1481.664 | Do dn v ompoc pidqzmnvggt vxfijrgzybzy, |
| 24 | 16 | 1595.148 | Zk zj r kilky lezmvijrccp rtbefncvuxvu, |
| 25 | 21 | 1931.346 | Uf ue m fdgft gzuhqdemxxk mowzaixqpsqp, |
Winning shift: 7; χ² = 14.029. Its full result matches Austen's sentence above. You can reproduce it with Decode at shift 7.
How the score is calculated
χ² = Σ (Oᵢ − Eᵢ)² / Eᵢ; Eᵢ = N × fᵢ / Σ f
For each letter A–Z, Oᵢ is its observed count, N is the total letter count and fᵢ is its reference English frequency. We use the same rounded Lewand frequency table as the site's frequency analysis tool, sourced from the letter frequency reference. Dividing by the sum normalizes those rounded frequencies. Case, punctuation, spaces and digits are ignored.
Lower means a closer letter distribution, not a probability that the text is correct. This is a ranking heuristic, not a statistical significance test. It does not check word order or meaning, and assumes English plaintext written with A–Z.
What changes when the ciphertext gets shorter?
Keep the same ciphertext and shift, remove non-letters, uppercase it, and take its first 40, 20, 10, 5 and 4 letters. Rank the same 25 candidate shifts each time. These are measured outputs for this one sentence.
| Letters | Top shift | Top χ² | Top plaintext | True shift rank | True shift χ² |
|---|---|---|---|---|---|
| 40 | 7 | 12.514 | ITISATRUTHUNIVERSALLYACKNOWLEDGEDTHATASI | 1 | 12.514 |
| 20 | 7 | 19.586 | ITISATRUTHUNIVERSALL | 1 | 19.586 |
| 10 | 7 | 15.328 | ITISATRUTH | 1 | 15.328 |
| 5 | 7 | 14.270 | ITISA | 1 | 14.270 |
| 4 | 22 | 14.800 | TETD | 2 | 17.034 |
In the displayed samples, the original shift stays first down to 5 letters. At 4 letters, the score favors shift 22 (“TETD”), while the true shift 7 ranks 2. A few letters can fit the reference distribution by chance. This illustrates the method's sampling limit, not a universal cutoff: another sentence or another prefix can change the order. Compare scores within a row, not across different lengths.
For a short message, inspect every candidate and use word boundaries or surrounding context. More ciphertext from the same key gives the frequency comparison more evidence; a longer sample still does not guarantee that the first-ranked result is right.
Brute-force attacks on classical ciphers: key spaces
Count the allowed keys before planning an exhaustive search. This comparison assumes the 26-letter alphabet and 1,000,000,000 keys/second (10⁹) for every cipher. This is an illustrative assumed rate, not a browser benchmark or a measured cracking speed.
Time to try every key = key count ÷ 10⁹ seconds
| Cipher | Key-space formula | Keys | Time for every key |
|---|---|---|---|
| ROT13 | 1 fixed shift (13) | 1 | 1 ns |
| Atbash | 1 fixed reversed alphabet | 1 | 1 ns |
| Caesar | 26 − 1 (exclude shift 0) | 25 | 25 ns |
| Affine (all key pairs) | 12 × 26 | 312 | 312 ns |
| Affine (non-identity) | 12 × 26 − 1 | 311 | 311 ns |
| Keyword / simple substitution | 26! = 26 × 25 × … × 1 | ≈ 4.03 × 10^26 | ≈ 1.28 × 10^10 years |
| Vigenère (n = 3) | 26^3 | 17,576 | 17.576 μs |
| Vigenère (n = 5) | 26^5 | 11,881,376 | 11.8814 ms |
| Vigenère (n = 8) | 26^8 | 208,827,064,576 | 3.480 minutes |
ROT13 and Atbash each fix one mapping. For Affine, y = ax + b (mod 26): a must be coprime to 26, giving 12 multipliers, while b has 26 choices. That makes 312 pairs; excluding just (a, b) = (1, 0) gives 311 non-identity pairs, including the 25 non-trivial Caesar shifts. See the Affine cipher derivation.
For simple substitution, there are 26 choices for the first replacement letter, 25 for the next, and so on: 26! alphabets, including the identity. The keyword row counts unrestricted substitution alphabets; searching only dictionary keywords would be a smaller, dictionary-dependent task. Different keywords can produce the same alphabet.
For Vigenère, a key of exactly n letters has 26ⁿ possible strings, including strings with a shorter repeating period and the all-A identity. If n is unknown, search each candidate length as well. Times here cover every key, not an average successful search; years use 365.25 days. The calculation omits message length, scoring cost and hardware differences, so equal rates do not imply equal real workloads.
The huge substitution space does not make it modern security: frequency and word-pattern attacks avoid enumerating every alphabet. Use the frequency analysis tool to inspect those patterns.
How to use Brute Force Decoder on this page
- In the tool's Mode menu, choose Brute Force Decoder.
- Paste ciphertext into Input Text. All 25 non-trivial decryptions appear in the output automatically.
- Read the list in shift order, 1–25. The tool lists candidates; it does not calculate or rank scores. The worked tutorial table above is separately ranked by English frequency.
- Use Copy or Download to save the full list. The shift slider and Swap are disabled in this mode.
- For just one result, choose Decode and set Shift Value to the candidate's shift. For ROT13, set it to 13.
Encode adds the shift; Decode subtracts it, wrapping around A–Z. For example, shift 3 maps A to D and Z to C. Case, spaces, digits and punctuation are preserved. Applying shift 13 twice makes a full 26-letter turn, which is why the same operation encodes and decodes ROT13.
History and sources
Suetonius describes Caesar replacing A with D and the remaining letters in the same way in private correspondence (Life of Julius Caesar, 56). That is the shift-3 pattern associated with his name. The example here uses the modern 26-letter English alphabet and shift 7 so you can follow a different key through encryption and recovery.
- Suetonius, Life of Julius Caesar, 56; also summarized in Caesar cipher — history and breaking the cipher.
- Jane Austen, Pride and Prejudice, chapter I — Project Gutenberg: the exact plaintext, with a line break joined.
- Letter frequency: the rounded English reference table attributed to Robert Lewand, Cryptological Mathematics (2000), used by the shared scorer.
- Affine cipher: the coprime multiplier rule and 12 × 26 key count.
Frequently asked questions
How do I use a Caesar cipher brute force decoder?
Select Brute Force Decoder in the Mode menu and paste the ciphertext. The output lists shifts 1–25 in numeric order; it does not rank them. Read the candidates for sensible words and grammar. Copy and Download save the whole list. To isolate one result, choose Decode and set its shift.
How many keys does a Caesar cipher have?
For the 26-letter English alphabet there are 26 shifts if you include shift 0, which leaves the text unchanged. Excluding that identity gives 25 non-trivial keys. Shift 26 is the same as shift 0, not an extra key.
How does Caesar cipher brute force find the right shift?
Try each shift and compare the resulting text with English. The worked table ranks candidates by chi-squared letter frequency: lower is closer to the reference distribution. Its winning shift is 7, with a score of 14.029. Confirm the words and meaning; the score is not a probability or a guarantee.
Do I need brute force to decode ROT13?
ROT13 specifies shift 13, so there is only one transformation to try. Choose Decode and set Shift Value to 13. Applying ROT13 a second time restores the original text. If you only know the message is a Caesar cipher, try all 25 non-trivial shifts, including 13.
Why can frequency ranking choose a different shift for short text?
Short samples have uneven letter counts, so the closest English-frequency match need not be the original text. In the displayed prefixes, shift 7 ranks first at 40, 20, 10 and 5 letters; at 4 letters, shift 22 ranks first and the original shift ranks 2. This is a property of this sample and scoring method, not a universal length cutoff.
Can you brute force a substitution cipher?
In principle, yes: an unrestricted substitution over A–Z has 26! possible alphabets, about 4.03 × 10^26. Exhaustively trying them is impractical even at the assumed billion keys per second in the comparison table. Solvers instead use letter frequencies, word patterns and heuristic searches. A dictionary-only keyword search covers a smaller set than all substitution alphabets.