Clever Quest Lab ← Labs

Vigenère Cipher

Encrypt with a keyword, step through the tabula recta, then crack the cipher.

Samples:

Letters A–Z
0
Key length
0
IC of input
–
IC of result
–

inputresultLetter frequencies in % of all letters. IC = index of coincidence (English ≈ 0.066, random letters ≈ 0.038).

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 open tab, direction, letter and output format options and animation speed on this device.

Added

How to use it

The lab has three parts. Encrypt & decrypt works while you type: choose a direction, type a keyword and type or paste a text. Only the letters A–Z change and their case is kept. Digits, spaces and punctuation are copied unchanged and do not use up a key letter. Letters with diacritics such as č, é or ô are first turned into plain letters; switch that off and they are copied unchanged, like punctuation.

Step by step shows the same text one letter at a time on the tabula recta. Crack it recovers an unknown key from the ciphertext alone: press “New mystery message” or bring your own ciphertext from the first tab.

Controls

How it works

Number the letters A = 0 to Z = 25 and repeat the keyword under the letters of the text. With a key of length m:

Ci = (Pi + Ki mod m) mod 26     Pi = (Ci − Ki mod m) mod 26

With the key LEMON, ATTACK AT DAWN becomes LXFOPV EF RNHR. The tabula recta is the same sum as a table: the key letter picks the row, the plaintext letter the column, and the cell holds the ciphertext letter. One plaintext letter turns into several different ciphertext letters, so letter counts look flat. The weakness is that the key repeats.

Kasiski examination. The same piece of plaintext under the same part of the key gives the same ciphertext. The lab lists the three-letter sequences that occur more than once and the distances between them; the key length divides most of these distances. Small numbers such as 2 and 3 always score well, so look for the largest well-supported factor.

Index of coincidence. The IC is the chance that two letters picked from the text are the same, where ni counts each letter and N is the number of letters:

IC = Σ ni(ni − 1) / (N(N − 1))

English prose gives about 0.066, random letters 1/26 ≈ 0.0385. For each length from 1 to 20 the lab splits the ciphertext into columns (every m-th letter) and averages their IC; at the right length every column keeps the English value. The suggestion is the smallest length that reaches 92 % of the best average, counting only lengths with at least 15 letters per column. William Friedman’s rough estimate uses the whole text: m ≈ (0.066 − 0.0385) / (IC − 0.0385).

Frequency analysis. Each column is now a simple shift cipher, the one you can crack in the Caesar Cipher lab. For each possible key letter the lab decrypts the column and compares its letter counts O with the counts E expected in English, χ² = Σ (O − E)² / E. The lowest score wins. The English frequencies are the widely used table published by Robert Lewand in Cryptological Mathematics (2000).

Things to try

Frequently asked questions

Who invented the Vigenère cipher?

Giovan Battista Bellaso described it in 1553. It was later credited to Blaise de Vigenère, who published a stronger autokey cipher in 1586. The square table goes back to Johannes Trithemius in the early 1500s. For about three centuries the cipher was widely thought to be unbreakable.

Who broke it?

Charles Babbage is known to have broken it in the 1850s, but he never published his method. Friedrich Kasiski published the repeat method in 1863, and William Friedman introduced the index of coincidence in the 1920s.

Can it be made unbreakable?

Yes, with a truly random key that is at least as long as the message and used only once. Then nothing repeats and every plaintext of that length is equally likely: the cipher becomes a one-time pad, the same idea as the Vernam cipher, which Claude Shannon proved unbreakable in the 1940s. The random key here comes from a cryptographically secure generator, not from a physical random source.

Why does the crack fail on short texts?

A 120-letter text with a 7-letter key leaves about 17 letters per column, too few for reliable counts. The lab warns when columns hold fewer than 40 letters.

Sources