Vigenere key recovery

Vigenère Cipher Frequency Analysis Explained

Frequency analysis becomes useful against a repeating-key Vigenère cipher after the period is known or strongly suspected. Before that point, several shifted alphabets are mixed together and the frequency distribution of the ciphertext as a whole is difficult to interpret.

Once the period is known, the situation changes completely.

If the period is 4, positions 1, 5, 9, 13… were all encrypted with the same key letter. Positions 2, 6, 10, 14… were encrypted with another, and the same pattern continues for the remaining key positions.

Separating those positions turns one polyalphabetic ciphertext into four smaller Caesar-shifted streams. Frequency analysis can then be applied to each stream independently.

That is the focus of this article. Methods for discovering the period belong to an earlier stage of the Vigenère cryptanalysis process .

If you already know the complete key and only need to decrypt a message, the Vigenère Cipher Decoder and Encoder performs that operation directly.

Start with the period, not with the most common letter

Suppose analysis has already established that a ciphertext has a likely period of 4.

Number the ciphertext letters from 1:

Position: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 … Ciphertext: H P Q R L K D C A B M R L T K W …

Do not count frequencies across that complete sequence yet.

Instead, extract four streams:

Column 1 → positions 1, 5, 9, 13, 17… Column 2 → positions 2, 6, 10, 14, 18… Column 3 → positions 3, 7, 11, 15, 19… Column 4 → positions 4, 8, 12, 16, 20…

Each column corresponds to one position of the repeating key.

If the period really is 4, every character within Column 1 received one fixed shift, every character within Column 2 received another fixed shift, and so on.

Vigenère frequency analysis diagram showing ciphertext with period four separated into four columns, each encrypted by one recurring Caesar shift
With a period of four, every fourth ciphertext letter belongs to the same key position. Separating those positions produces four Caesar-shifted streams that can be analyzed independently.

A controlled example: four unknown key letters

Consider a 744-letter English sample encrypted with a four-letter Vigenère key.

The analyst knows the period is 4 but does not know the key letters. The ciphertext begins:

HPQRLKDCABMRLTKWEAFYOQQWLZQTPIFMYOWIJKUTSMDXSMGWPNGPAIFXPZZWLZQS QBQRSQPHPVGREQXXSMFIIBUWCMAVRIZMKMPEWWZKXMEWLOQKTDQWPIOLVMKTZAUX TWZIYWGKSTQXEMDWQWDXSMTEMQFWZNQR…

Splitting it according to period 4 gives four streams of 186 letters each.

Column First characters Characters in stream
1 HLALEOLPYJSSPAPLQSPESICRKWXLTP… 186
2 PKBTAQZIOKMMNIZZBQVQMBMIMWMODI… 186
3 QDMKFQQFWUDGGFZQQPGXFUAZPZEQQO… 186
4 RCRWYWTMITXWPXWSRHRXIWVMEKWKWL… 186

The problem has now changed.

Instead of guessing one four-letter Vigenère key from all possible combinations, we can ask four much smaller questions:

What Caesar shift produced Column 1? What Caesar shift produced Column 2? What Caesar shift produced Column 3? What Caesar shift produced Column 4?

First look: count the letters in each column

Frequency analysis begins by counting how often each ciphertext letter occurs in a stream.

The six most common letters in the four example columns are:

Column Most frequent ciphertext letters
1 E (21), P (20), D (16), S (15), C (15), L (11)
2 M (37), I (20), Q (18), B (16), Z (12), A (11)
3 Q (25), Z (20), A (17), F (16), D (15), E (13)
4 I (24), X (19), R (17), W (16), E (16), M (15)

Since E is usually the most frequent letter in long English text, a common beginner technique is to assume that the most frequent ciphertext letter in each column represents plaintext E.

That shortcut gives:

Column Most frequent ciphertext letter If assumed to be plaintext E
1 E Shift A
2 M Shift I
3 Q Shift M
4 I Shift E

Three of those guesses are correct.

The first is not.

Why “most common letter = E” can fail

In Column 1 of this example, the most frequent plaintext letter happens to be T, not E.

The actual plaintext counts behind that column begin:

T = 21 E = 20 S = 16 H = 15 R = 15 A = 11

The correct key shift moves plaintext T to ciphertext E.

If an analyst automatically declares ciphertext E to represent plaintext E, the inferred shift is zero and the first key letter is wrong.

English frequency tables describe long-run tendencies, not rules that every sample must obey.

A column contains only every fourth letter of the original message. Its sample is therefore smaller than the complete plaintext and may have a noticeably different ranking of common letters.

The safest use of a high-frequency ciphertext letter is as a candidate generator, not as proof of a shift.

Compare the whole frequency distribution instead

A stronger approach evaluates how well each possible Caesar shift makes the entire column resemble the expected distribution of the plaintext language.

For an English A–Z ciphertext column there are only 26 possible shifts. For each one:

decrypt the column with a candidate shift ↓ count A through Z ↓ compare the observed counts with expected English frequencies ↓ assign a score to the fit

One common scoring method is Pearson’s chi-squared statistic:

χ² = Σ (Observedᵢ – Expectedᵢ)² / Expectedᵢ

For each letter, Observedᵢ is how many times that letter appears after applying the candidate shift, while Expectedᵢ is the count predicted from an English frequency model for a stream of that length.

A lower score means the decrypted distribution is closer to the reference distribution.

The exact numeric score is not a universal measure of correctness. It depends on the sample length and reference frequencies. Its main value here is comparing the 26 candidate shifts for the same column.

Recover the first key letter from the full distribution

Column 1 defeated the simple E assumption, so it is a good test of the stronger method.

Score all 26 possible shifts against standard English letter frequencies.

The strongest candidate is shift 11:

Shift 11 → χ² ≈ 31.42

Under the usual Vigenère numbering:

A = 0 B = 1 C = 2 … L = 11

So the first key letter is:

Column 1 → shift 11 → key letter L

Decrypting Column 1 by 11 positions produces a distribution led by:

T = 21 E = 20 S = 16 H = 15 R = 15 A = 11

That profile is much more plausible as an English sample than the unchanged ciphertext distribution, even though E is not the single most common letter.

The full distribution rescued the analysis from a wrong one-letter assumption.

Repeat the process for every key position

Apply the same scoring process independently to Columns 2, 3, and 4.

Column Best shift Best key letter Chi-squared score
1 11 L 31.42
2 8 I 32.07
3 12 M 29.06
4 4 E 37.07

Reading the recovered shifts in column order gives:

11, 8, 12, 4

Converting those values back to letters gives:

L I M E

The recovered Vigenère key is therefore:

LIME

Recombine the columns before trusting the key

Statistical scoring provides candidate shifts. The final test is whether those shifts work together when returned to their original positions.

Repeating the recovered key:

L I M E L I M E L I M E L I M E …

and decrypting the original ciphertext begins to produce:

WHENACRYPTANALYSTSTUDIESAREPEATINGKEYCIPHERTHEUSEFULPATTERNSAREOFTENHIDDENUNTILTHETEXTISREORGANIZED…

Restoring spaces:

WHEN A CRYPTANALYST STUDIES A REPEATING KEY CIPHER, THE USEFUL PATTERNS ARE OFTEN HIDDEN UNTIL THE TEXT IS REORGANIZED…

That coherent reconstruction is stronger evidence than any isolated frequency peak.

Key recovery should therefore be treated as a two-level problem:

column level → does each shift fit the expected letter distribution? message level → do the recovered shifts produce coherent plaintext together?

Why a wrong period makes frequency analysis look weak

Frequency analysis assumes that each extracted column was encrypted by one fixed Vigenère shift.

If the candidate period is wrong, that assumption breaks.

Suppose the real period is 4 but the ciphertext is split as though the period were 3.

One extracted stream might contain characters originally encrypted by key positions 1, 4, 3, 2, 1, 4, and so on.

Instead of one Caesar-shifted distribution, several shifted distributions become mixed inside the same column.

correct period → one recurring key shift per column → recognizable language distribution wrong period → several key shifts mixed in a column → flattened or inconsistent distribution

Poor frequency fits across nearly every column can therefore be evidence that the proposed period is wrong, not merely that frequency analysis has failed.

This provides a useful feedback loop between period estimation and key recovery.

Multiples of the real period behave differently

Not every incorrect-looking period contaminates the streams.

If the true period is 4 and the ciphertext is divided using period 8, each real key position is split into two smaller groups.

Positions:

1, 5, 9, 13, 17, 21…

all use the first key shift.

Under a period-8 split, they become:

1, 9, 17, 25… 5, 13, 21, 29…

Both substreams still use the same underlying shift.

Frequency analysis may therefore work at a multiple of the true period, but each column contains fewer letters and becomes noisier.

If two or more recovered key positions repeatedly produce the same shift in a shorter pattern, check whether the apparent key has a smaller fundamental period.

Column length matters more than total ciphertext length

A Vigenère ciphertext can look long while still providing weak frequency evidence for each individual key position.

What matters after splitting is approximately:

characters per column ≈ ciphertext length / period

A 600-letter ciphertext with period 3 gives about 200 letters per stream.

600 / 3 = 200

The same ciphertext with period 20 gives only about 30:

600 / 20 = 30

Thirty letters are much more vulnerable to sampling noise. A common letter may be underrepresented, an uncommon letter may appear several times by chance, and several candidate shifts may receive similar scores.

Situation Effect on frequency analysis
Long column Observed frequencies tend to resemble the language model more closely.
Short column Random variation can make the best shift ambiguous.
Wrong period Multiple shifts may be mixed into one stream.
Period that is a multiple of the true period Streams can remain valid but become unnecessarily short.

A low statistical score is evidence, not a command

Automated frequency analysis often ranks one shift first, one second, and one third.

With a long clean column, the winning candidate may be dramatically better than every alternative.

With a short column, the top two candidates may be close.

In that situation, fixing the first-ranked shift immediately can damage the rest of the reconstruction.

Keep several plausible candidates for an uncertain column and test them in the context of the reconstructed message.

Column 1 → L strongly preferred Column 2 → I strongly preferred Column 3 → M or X both plausible Column 4 → E strongly preferred

The partial key:

LI?E

may already produce enough recognizable structure to decide between competing candidates for the third position.

Statistical analysis and linguistic validation work better together than either does alone.

Word frequencies do not live inside the columns

Single-letter statistics are especially useful inside an individual Vigenère column because every character in that stream is separated from the next by the key period in the original plaintext.

Normal adjacent-letter relationships are broken when the text is extracted this way.

If the period is 5, a column contains positions:

1, 6, 11, 16, 21…

Those letters were not normally adjacent in the original sentence.

Searching such a column for ordinary English bigrams such as TH or HE can therefore be misleading.

Bigrams, trigrams, likely words, and sentence structure become more useful after candidate column shifts have been recombined into their original message order.

That distinction prevents a common analytical mistake: using whole-language sequence statistics on text that is no longer arranged in whole-language sequence order.

The language model has to match the plaintext

English frequency analysis assumes the underlying message is English or sufficiently similar to the English reference distribution.

If the plaintext is French, German, Spanish, or another language, its characteristic letter frequencies differ.

Even within English, specialized text can distort the expected distribution. Source code, lists of names, abbreviations, DNA-like sequences, or deliberately constrained writing may behave very differently from ordinary prose.

A poor English-frequency score does not prove that a Vigenère shift is wrong if the language assumption itself is wrong.

For serious analysis, the reference distribution should match the probable plaintext source as closely as practical.

Normalize the text consistently

The extraction process must follow the same character-counting rule that was used when the Vigenère key advanced during encryption.

In a standard classical A–Z treatment, spaces and punctuation are often ignored:

MEET AT NINE. ↓ MEETATNINE

If the key advances only on letters, counting a space as a key position during analysis shifts every later column assignment and corrupts the frequency streams.

A custom implementation may use different rules, so the important point is consistency rather than blindly deleting every non-letter character.

If all columns unexpectedly produce poor results, check key alignment and normalization before assuming the cryptanalytic method is wrong.

Frequency analysis is not the same as guessing the whole key

A four-letter Vigenère key has:

26⁴ = 456,976

possible A–Z strings.

Frequency analysis does not need to evaluate all 456,976 complete keys.

Once the period is known, the problem separates into four independent Caesar shifts, each with only 26 possibilities:

Column 1 → test 26 shifts Column 2 → test 26 shifts Column 3 → test 26 shifts Column 4 → test 26 shifts

More importantly, those candidates are not judged blindly. They are ranked according to how well the resulting letter distributions match the expected plaintext language.

This decomposition is what makes the repeated-key structure so damaging to Vigenère security.

What a convincing recovery looks like

One high-frequency letter is weak evidence.

A whole-column distribution that strongly favors one Caesar shift is better.

Several independently analyzed columns producing a coherent repeated key are better again.

And when that recovered key reconstructs readable plaintext across the entire ciphertext, the pieces reinforce one another.

known or plausible period ↓ separate recurring key positions ↓ analyze the full frequency distribution of each column ↓ rank Caesar shifts ↓ convert shifts to candidate key letters ↓ recombine the columns ↓ validate the reconstructed plaintext

That is the practical role of frequency analysis in repeating-key Vigenère cryptanalysis. It does not normally solve the original mixed ciphertext directly. It becomes powerful only after the periodic structure has been exposed and the polyalphabetic cipher has been separated back into the simpler substitution streams from which it was built.

Written by Marcus Hale

Editorially reviewed by VigenereDecoder.com editorial team

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *