Caesar cipher decoder with automatic shift detection
Break a Caesar shift without guessing. ctfpal scores all 26 rotations by chi-squared letter frequency and puts the English one first.
Open in ctfpalA Caesar cipher shifts every letter by a fixed amount. There are only 25 useful keys, so it is trivially breakable by trying all of them - the only real question is which of the 25 candidates is the right one, and that is a question you should never answer by reading them yourself.
Why chi-squared beats eyeballing
English letter frequencies are stable: E around 12.7%, T around 9.1%, Z under 0.1%. Score each of the 26 rotations against those expected frequencies with a chi-squared statistic and the correct shift usually wins by a wide margin. The advantage over scanning by eye grows with the length of the text and, crucially, it does not degrade when the plaintext is unusual - a shifted flag full of digits and underscores still scores correctly on its letters alone.
EXPECTED = {'a': 0.0817, 'b': 0.0150, ...} # English unigram frequencies
def chi_squared(text):
letters = [c for c in text.lower() if c.isalpha()]
n = len(letters)
score = 0.0
for ch, expected_freq in EXPECTED.items():
expected = expected_freq * n
observed = letters.count(ch)
score += (observed - expected) ** 2 / expected
return score # lower is more English-like
best = min(range(26), key=lambda k: chi_squared(rotate(ct, k)))When the shift is not 13
Short ciphertexts - under about 30 letters - are where statistics get unreliable, because a single unusual word skews the distribution. ctfpal still ranks all 26 and shows them, so a short text becomes a list to skim rather than a set of 26 separate round trips to a website.
Worked example
A shifted flag
Input
cvpbPGS{arire_gehfg_n_pnrfne}Result
picoCTF{never_trust_a_caesar}Shift 13. Note that digits and punctuation pass through untouched, which is why the braces still look like braces.
Load this example in the workspaceCommon questions
- What if the alphabet includes digits?
- Some challenges rotate over a 36- or 62-character alphabet so digits shift too. If a plain 26-letter rotation leaves the letters right but the digits wrong, that is what happened; the ctfpal cipher tab exposes the alphabet so you can widen it.
Part of a module
2. Classical ciphers and frequency analysis
Break Caesar, Vigenere, and arbitrary substitution using letter statistics - and learn why statistics beat guessing.
Practise on real challenges
Go deeper
- Chi-squared, index of coincidence, and why classical ciphers fallCaesar, Vigenere, and substitution ciphers do not need guesswork - they need two statistics. How chi-squared scores a candidate plaintext, how the index of coincidence recovers a key length, and how to combine them into an attack that runs in milliseconds.
Related tools
ROT13 decoder
Apply ROT13 (and ROT47) instantly. ROT13 is its own inverse, so the same operation encodes and decodes.
Vigenere cipher solver with automatic key recovery
Decrypt Vigenere with a known key, or recover the key from ciphertext alone using index-of-coincidence period detection and per-column chi-squared.
Atbash cipher decoder
Decode Atbash, the keyless substitution that maps A to Z, B to Y, and so on. Its own inverse.
Cipher identifier and automatic decoder
Paste anything and find out what it is. ctfpal runs every decoder and rotation, including multi-pass cascades, and ranks results by English-likeness and flag patterns.