Clever Quest Lab ← Labs

Caesar Cipher

Shift every letter by a secret number, then crack it the way codebreakers do: by counting letters.

A → D

Samples:

Only A–Z and a–z are shifted, and case is kept. Everything else passes through unchanged unless you pick “Letters only”.

Cipher wheel

Result:

Highlighted: A → D

Outer ring: plain letters. Inner ring: cipher letters. Drag the inner ring to turn it, or focus the wheel and use the arrow keys.Outer ring: plain letters. Inner ring: cipher letters. Drag the inner ring with your finger to change the shift.Outer ring: plain letters. Inner ring: cipher letters. Drag the inner ring with the mouse, or click it and use the arrow keys.

Alphabet strip

Top: plain letter. Bottom: cipher letter. The letter before the text cursor is highlighted.

Crack it: frequency analysis

The attacker sees only the ciphertext. It tries all 26 shifts and scores how English each result looks (lower χ² = more English).

No letters Nothing to analyse yet

Drag down to see how short texts fool the attack.
Letters analysed
0
Index of coincidence
–
Lowest χ²
–
Runner-up
–

Index of coincidence: English ≈ 0.066, random letters ≈ 0.038. A shift never changes it.

χ² score for every shift

Log scale. The shortest bar is the most English-looking decryption (marked “best”); the triangle marks the shift on the wheel.

Letter frequencies: ciphertext vs English

Ciphertext letters (% of the letters analysed)English letters, moved by the wheel shift (3)

Upper labels: cipher letters. Lower labels (small): the plain letter each one becomes with the wheel shift. At the right shift the outlines sit on the bars.

All 26 shifts (brute force)

    Runs on your device. Nothing you type or record is uploaded. Keeps working without a connection while the page is open. Works with touch. Saves only the shift, the output and accent options and the crack panel view on this device.

    Added

    How to use it

    Type or paste a message into the upper box. Every letter moves the same number of places along the alphabet, wrapping from Z back to A, and the result appears below as you type. That number, the shift, is the key: turn the cipher wheel, press minus or plus, or type a number from 0 to 25. Switch to Decrypt to turn a secret message back with the same key.

    Case is kept. Digits, spaces and punctuation pass through unchanged unless you choose “Letters only” or the classic “groups of 5”. Accented letters such as á, č or ž stay as they are by default; the other option removes the accents first, so they are shifted like plain letters. Letters with no plain form, such as ß or ł, never change.

    The crack panel below plays the attacker: it sees only the ciphertext and scores all 26 shifts for how English they look.

    Controls

    How it works

    Number the letters A = 0, B = 1, …, Z = 25. With shift k:

    E(x) = (x + k) mod 26      D(y) = (y − k) mod 26

    With Caesar’s shift of 3, A becomes D and X wraps round to A. Only 26 shifts exist, so trying them all (the brute-force list) is easy even by hand.

    The score is the chi-squared statistic. For a trial shift s, count each cipher letter i (Oi, out of N letters) and compare it with the count English would give, Ei = N · p(i − s), where p is the English frequency of the plain letter that would sit there:

    χ²(s) = ∑ (Oi − Ei)² / Ei   (sum over the 26 letters)

    The lowest score is the automatic guess. The English frequencies come from a standard published table (Robert Lewand, Cryptological Mathematics, 2000): E 12.7 %, T 9.1 %, A 8.2 % … Z 0.07 %. A shift slides this pattern along the alphabet without changing its shape, so at the right shift the English outlines sit on the bars. For the same reason the index of coincidence, the chance that two letters picked at random from the text match, is unchanged by encryption: about 0.066 for English, 0.038 for random letters.

    Short texts break the method. With a dozen letters most counts are 0 or 1, and several shifts fit almost equally well. With about 10 letters the lowest score is often wrong; from about 30 letters of ordinary English it is almost always right. “Confident” means at least 20 letters and a runner-up score at least twice as high.

    Things to try

    Frequently asked questions

    Did Julius Caesar really use it?

    The source is the Roman historian Suetonius, writing in the early second century AD. He says that Caesar’s confidential letters put D in place of A, a shift of three, and that Augustus wrote B for A.

    Is the Caesar cipher secure?

    No. It has only 25 useful keys, and frequency analysis finds the right one from a few dozen letters. The earliest known description of frequency analysis is by the Arab scholar al-Kindi in the 9th century. Its unbreakable cousin, the Vernam cipher or one-time pad, gives every letter its own random shift from a key as long as the message, used only once.

    What is ROT13?

    Shift 13. Applying it twice gives back the original, so one button encodes and decodes. It became popular in online discussion groups in the early 1980s for hiding punchlines and spoilers, not secrets.

    Why does the crack sometimes pick the wrong shift?

    The score only measures how English the letter counts look. Very short messages, many rare letters, other languages or text that is not a Caesar cipher can all make a wrong shift win.

    Sources