Vigenère cipher reference

Kasiski vs IC vs Friedman vs Autocorrelation: Which Finds the Vigenère Key Length Best?

Finding the repeating period is one of the most important steps in ciphertext-only Vigenère cryptanalysis.

It is also one of the easiest places to become overconfident.

A repeated sequence may point to several factors. An Index of Coincidence peak may occur at a multiple of the real period. Autocorrelation can produce an even stronger peak at twice or three times the fundamental period. A Friedman estimate can land between plausible integers rather than directly on the key length.

So which method should you trust?

To make the comparison concrete, this article applies four methods to the same 2,444 Vigenère ciphertext samples:

  • Kasiski factor analysis
  • average-column Index of Coincidence
  • the Friedman estimate
  • ciphertext autocorrelation

Each method searches candidate periods from 2 through 20.

Across the full benchmark, that produces:

2,444 ciphertext samples
× 4 key-length methods
= 9,776 method evaluations

The result is not that one technique makes the others obsolete.

The useful finding is more specific:

average-column IC was the most consistently useful shortlist generator across the benchmark, while Kasiski became exceptionally strong once repeated sequences were plentiful. Autocorrelation supplied valuable periodic evidence but frequently preferred harmonics. Friedman was useful as a rough independent estimate, but was the weakest exact candidate ranker in this particular experiment.

If you want to analyze an actual ciphertext, start with the Vigenère Cipher Decoder and Encoder. The comparison below is about what the four period-finding methods contribute and where each can mislead.

This benchmark asks a different question from the previous one

The earlier ciphertext-length benchmark measured key recovery after giving the cracker the true period.

This experiment removes that advantage.

The plaintext corpus, keys, ciphertext lengths, and block construction are kept the same so the underlying material does not change. But the true period is hidden from each method.

The question is now:

If candidate periods 2 through 20 are available, how highly does each method rank the real fundamental period?

That isolates period detection rather than the later problem of recovering the individual key letters.

The full attack still requires both stages. They should not be treated as the same statistical problem.

The four methods are measuring different things

Before comparing percentages, it helps to understand why disagreement is normal.

Method Main signal Typical strength Typical ambiguity
Kasiski Distances between repeated ciphertext sequences Concrete periodic evidence Divisors and accidental repeats
Average-column IC Language-like coincidence after splitting by a candidate period Uses all ciphertext letters Multiples of the true period can also score highly
Friedman Whole-ciphertext IC converted into an estimated period Fast single-number estimate Approximation can be noisy or unstable
Autocorrelation Matches between ciphertext and shifted copies of itself Direct periodic peak detection Peaks often appear at multiples of the period

These are not four versions of one statistic.

They observe different consequences of the same repeated-key structure.

For deeper treatments of the individual techniques, the site already has dedicated guides to the Kasiski examination, Index of Coincidence, and Friedman test. This article keeps their theory brief and concentrates on comparative behavior.

Benchmark corpus and keys

The benchmark reuses the exact normalized English corpus from the previous experiment.

The source is Chapter I of Lewis Carroll’s Alice’s Adventures in Wonderland, using Project Gutenberg eBook #11.

After converting to uppercase and retaining only A–Z, the benchmark corpus contains:

6,498 letters

SHA-256:

3070aad2cd74ac31a8a6a39c2ecc780392bbe9291904b599d41a352585b0957e

Four primitive repeating keys were used:

Key Fundamental period
SUN 3
ORBIT 5
COMPUTER 8
CRYPTOGRAPHY 12

“Primitive” matters here.

A written key such as DOGDOG has length 6 but a fundamental period of 3. The methods in this article are trying to identify the fundamental repeating period.

None of the four benchmark keys has a shorter repeating subperiod.

Ciphertext lengths and trial count

The tested ciphertext lengths were:

30
50
75
100
150
200
300
500
800

For each length, the 6,498-letter corpus was divided into consecutive non-overlapping full blocks. Any incomplete final block was discarded.

Each block was encrypted independently from the first letter of the relevant key.

That produces:

Ciphertext length Blocks per key Total ciphertexts across four keys
30 216 864
50 129 516
75 86 344
100 64 256
150 43 172
200 32 128
300 21 84
500 12 48
800 8 32

Total:

2,444 ciphertext samples

Every one of those samples was evaluated by all four methods.

How candidate periods were ranked

A comparison is only meaningful if the decision rules are explicit.

All methods considered:

periods 2 through 20

No method was told which of those candidates was correct.

Kasiski implementation

A naive repeated-n-gram scanner can count one long repeated block many times as overlapping trigrams, tetragrams, and longer fragments.

That would inflate its evidence.

The benchmark therefore scans for maximal exact matching runs of at least three letters at each ciphertext distance.

Suppose one repeated region contains:

ABCDEFG

at two positions.

That repeated block contributes its spacing once. It is not separately counted as:

ABC
BCD
CDE
DEFG
ABCDE
...

For every recorded repeat distance, candidate period k receives one vote if:

distance mod k = 0

Higher vote counts rank higher.

If the true period receives zero votes, Kasiski is recorded as providing no support for that period.

This is one reproducible Kasiski implementation, not the only possible one.

Average-column Index of Coincidence

For candidate period k, the ciphertext is split into k positional streams.

The raw IC is calculated separately for each stream:

IC = Σ fᵢ(fᵢ - 1) / N(N - 1)

The k stream values are then averaged.

Candidates with the larger average column IC rank higher.

This follows the key idea behind IC period testing: when the split matches the repeating key structure, each column behaves more like a monoalphabetically shifted sample of the underlying language.

Friedman estimate

The benchmark uses the same English constants as the site’s dedicated Friedman article:

m ≈ 0.027N / ((N - 1)IC - 0.038N + 0.065)

This produces a real-valued period estimate rather than a score for every candidate.

To place Friedman in the same ranking framework, candidate periods 2–20 are ordered by their absolute distance from the estimate.

For example, if:

m ≈ 6.37

the closest candidates begin:

6, 7, 5, 8...

If the formula’s denominator is non-positive, the trial has no finite Friedman ranking.

Autocorrelation

For candidate shift d, the ciphertext is compared with a copy shifted by d positions.

The score is:

A(d) = matching positions / (N - d)

or, explicitly:

A(d) = Σ [Cᵢ = Cᵢ₊d] / (N - d)

Candidates with higher match rates rank higher.

If d matches the key period or one of its multiples, the same key letters realign. That can raise the coincidence rate.

The same property also creates one of autocorrelation’s main interpretation problems: a multiple of the true period can produce a stronger peak than the fundamental period itself.

How success was scored

The benchmark does not force an arbitrary tie-break between candidates with equal scores.

Candidates with equal evidence share the same competition rank.

A true period receives rank 1 when no candidate has a strictly better score.

It is counted in the “top-three rank” metric when no more than two candidates have strictly better evidence.

For Kasiski, zero votes are not treated as a meaningful ranking.

This metric is intentionally about producing a useful period shortlist rather than pretending every method naturally returns one unique integer.

That matters because harmonics are part of the problem, not an implementation nuisance to hide.

Main result: true period within the top-three rank

The table below shows how often the real fundamental period had rank 3 or better.

Ciphertext letters Kasiski Avg. column IC Friedman Autocorrelation
30 54/864 (6.2%) 312/864 (36.1%) 148/864 (17.1%) 252/864 (29.2%)
50 93/516 (18.0%) 227/516 (44.0%) 103/516 (20.0%) 187/516 (36.2%)
75 136/344 (39.5%) 219/344 (63.7%) 89/344 (25.9%) 135/344 (39.2%)
100 153/256 (59.8%) 191/256 (74.6%) 73/256 (28.5%) 112/256 (43.8%)
150 131/172 (76.2%) 136/172 (79.1%) 59/172 (34.3%) 87/172 (50.6%)
200 120/128 (93.8%) 99/128 (77.3%) 52/128 (40.6%) 74/128 (57.8%)
300 75/84 (89.3%) 71/84 (84.5%) 40/84 (47.6%) 46/84 (54.8%)
500 38/48 (79.2%) 40/48 (83.3%) 24/48 (50.0%) 30/48 (62.5%)
800 24/32 (75.0%) 27/32 (84.4%) 19/32 (59.4%) 23/32 (71.9%)

No method dominates every row.

That is more informative than a single overall percentage.

Average-column IC was the most consistent shortlist method

IC led the top-three metric at:

30
50
75
100
150
500
800 letters

Kasiski led at:

200
300 letters

The IC result is especially notable at short lengths.

At only 30 letters, exact language statistics are weak, yet the true period still reached the top-three rank in:

312 of 864 trials
36.1%

That is not a high success rate in absolute terms.

It is simply better than the other three methods under the same short-sample conditions.

At 100 letters, IC improved to:

191 / 256
74.6%

At 800 letters:

27 / 32
84.4%

Why does it not approach 100% even with long text?

Because the largest raw IC score is not guaranteed to occur at the fundamental period.

Multiples remain a persistent ambiguity.

Multiples are the central IC trap

Suppose the real period is 5.

Splitting the ciphertext into 5 columns groups identical key positions.

But splitting it into 10 columns also avoids mixing different key shifts.

It simply subdivides each valid period-5 stream.

So periods:

5
10
15
20

can all look statistically attractive.

This is visible in one 300-letter ORBIT sample from the benchmark.

The highest average-column IC scores were:

Candidate Average column IC
15 0.07860
20 0.07095
10 0.07011
5 0.06734

If a cracker blindly chose the largest IC score, it would report:

15

not:

5

Yet period 5 is clearly present in the same family of strong candidates.

That is why IC should usually generate period hypotheses, not be treated as “highest value equals key length.”

The fundamental period often requires checking divisors of stronger harmonic candidates.

Kasiski improved dramatically once repeats became plentiful

Kasiski behaved very differently.

At 30 letters, the true period received positive repeated-sequence factor support in only a small fraction of the samples.

Its top-three success rate was:

6.2%

At 50 letters:

18.0%

This is not surprising.

Kasiski needs useful repeated ciphertext fragments. A short message may simply not contain them.

By 150 letters, the top-three rate had risen to:

76.2%

At 200 letters:

93.8%

and at 300:

89.3%

In that middle range, Kasiski was the strongest method in this benchmark.

The important qualification is that its evidence is factor-based.

A repeat spacing produced by an eight-letter key is also divisible by:

2
4

if the spacing happens to be a multiple of 8.

Kasiski can therefore produce a strong factor family without uniquely telling you which factor is the fundamental period.

More text did not make the simple Kasiski ranking monotonically better

The Kasiski top-three rate fell from:

93.8% at 200 letters

to:

75.0% at 800 letters

That result should not be misread as “Kasiski gets worse when ciphertext gets longer.”

The benchmark used a deliberately simple, unweighted factor-vote implementation.

Longer text creates more genuine repeated sequences, but it also creates more accidental repeats and more distances carrying common small factors.

Composite periods make the issue especially visible.

For the period-12 key, distances produced by correct same-key alignments are also divisible by some combination of:

2
3
4
6

depending on the distance.

Small divisors can therefore accumulate large vote totals.

A more elaborate Kasiski implementation could weight repeat lengths, model accidental-repeat probability, combine GCD structure differently, or pass the candidate family into another statistical test.

The benchmark is measuring the stated algorithm, not proving an upper limit for Kasiski analysis.

Autocorrelation found periodicity, but harmonics often outranked the period

Autocorrelation was usable even when no repeated trigram existed.

That gives it an advantage over Kasiski on short samples.

Its top-three results rose from:

29.2% at 30 letters

to:

71.9% at 800 letters

But the raw maximum often landed on a multiple of the real period.

For the first 300 letters encrypted with SUN, period 3, the strongest autocorrelation shifts were:

Shift Match rate
6 0.10204
9 0.09622
12 0.09028
18 0.07092
3 0.07071

The true period is visible, but the stronger peaks are its multiples.

That is not a failure of the periodic model.

It is evidence of it.

Shifting by 6, 9, or 12 positions also realigns the three-letter key.

A practical autocorrelation analysis should therefore examine peak spacing and common divisors rather than interpreting the single tallest peak as the only answer.

Friedman behaved differently because it compresses the ciphertext into one estimate

The Friedman test does not search for repeated fragments or inspect each candidate’s columns.

It compresses the whole ciphertext into an IC-based period estimate.

That makes it fast and conceptually elegant.

It also makes it sensitive to finite-sample deviation from the assumptions built into its English and random-text constants.

In the 300-letter SUN example, Friedman performed beautifully:

estimate = 3.0093
true period = 3

For the same 300-letter plaintext encrypted with ORBIT:

estimate = 6.3696
true period = 5

The candidate ordering by distance begins:

6
7
5
8
...

So the true period is still a useful nearby hypothesis.

For COMPUTER, period 8:

estimate = 10.6813

For CRYPTOGRAPHY, period 12:

estimate = 7.6535

Those misses show why the estimate should not be treated as an oracle.

Across the benchmark, Friedman’s true-period top-three rate rose with ciphertext length:

17.1% at 30 letters
20.0% at 50
28.5% at 100
40.6% at 200
59.4% at 800

It remained below the other methods at most tested lengths, but it contributes something they do not: a rough period scale based only on the whole-text coincidence level.

That makes it useful as an independent cross-check.

One 300-letter sample shows why combining methods is stronger

Consider the first 300 normalized letters of the benchmark corpus.

Encrypt that identical plaintext four times, changing only the key.

SUN, period 3

Kasiski’s strongest factor was:

3

IC’s largest raw score occurred at:

15

but period 3 was also strongly elevated.

Autocorrelation’s highest peak was:

6

while 3 remained part of the periodic peak family.

Friedman estimated:

3.0093

The methods disagree on the tallest individual signal, but collectively they point toward a fundamental period of 3 and its multiples.

ORBIT, period 5

Kasiski’s strongest factor was:

5

IC ranked the harmonic family:

15, 20, 10, 5

Autocorrelation ranked:

10, 15, 20, 5

Friedman estimated:

6.3696

Here Kasiski gives the cleanest fundamental candidate, while IC and autocorrelation strongly reinforce the same multiple-of-5 structure.

COMPUTER, period 8

Kasiski scores began:

2 → 14 votes
4 → 13 votes
8 → 13 votes

IC began:

16 → 0.07480
8  → 0.07066

Autocorrelation began:

16 → 0.06690
8  → 0.06164

Friedman estimated:

10.6813

No single raw winner is perfect.

But periods 8 and 16 repeatedly appear in the strongest statistical evidence, while Kasiski also exposes their divisor structure.

CRYPTOGRAPHY, period 12

Kasiski’s leading votes went to smaller factors:

2, 3, 6

IC’s strongest candidate was:

12

Autocorrelation’s strongest shift was:

12

Friedman estimated:

7.6535

In this case the two coincidence-based candidate tests recover the fundamental period much more cleanly than the simple Kasiski vote or Friedman estimate.

The point is not that the methods “vote” democratically.

It is that their disagreement has structure.

Divisors and multiples should be investigated, not discarded

The benchmark repeatedly produced candidate families such as:

3, 6, 9, 12, 15, 18

or:

5, 10, 15, 20

or:

8, 16

A cracker should not treat those as unrelated guesses.

They are harmonically connected.

If 15 has the highest column IC, test its divisors:

3
5

If autocorrelation peaks at:

8
16

ask whether 8 explains both peaks.

If Kasiski strongly favors:

2
4
8

the result may be a factor family rather than three independent hypotheses.

The fundamental period is usually the smallest repeating unit that explains the evidence without mixing distinct key shifts.

That is a model-selection problem, not merely a maximum-score lookup.

So which method was best?

The answer depends on what “best” means.

Best general shortlist in this benchmark: average-column IC

IC produced the highest top-three rate at seven of the nine tested ciphertext lengths.

It worked without requiring literal repeated n-grams and remained useful across all four key periods.

Its main weakness was harmonic ambiguity.

A multiple of the true period often looked just as good or better than the fundamental period.

Best when useful repeats were abundant: Kasiski

Kasiski was poor on very short ciphertext because the evidence it needs often did not exist.

Once enough repeated sequence structure appeared, it became extremely informative.

At 200 letters, the true period had a top-three rank in:

120 of 128 samples
93.8%

The main weakness was factor ambiguity, especially for composite periods.

Best as a corroborating periodic signal: autocorrelation

Autocorrelation required no explicit repeated n-gram family and improved steadily as text length increased.

It was particularly useful for showing a repeating spacing pattern.

Its weakness was the same fundamental-versus-harmonic problem: multiples often produced taller peaks.

Best treated as a rough independent estimate: Friedman

Friedman was the least successful standalone ranker in this controlled comparison.

That does not make it useless.

It asks a different, compressed question: what key period is consistent with the overall coincidence level of the ciphertext?

When its estimate lands near a Kasiski, IC, or autocorrelation candidate family, it adds independent support.

When it disagrees sharply, that disagreement is a reason to inspect sample size, language assumptions, or harmonic candidates more carefully.

A practical sequence for real Vigenère analysis

The benchmark suggests a workflow more robust than choosing one favorite method.

Start with the ciphertext itself:

1. Normalize the text consistently.

2. Use Kasiski to look for concrete repeated-sequence spacings.

3. Calculate average-column IC across a reasonable candidate-period range.

4. Inspect autocorrelation peaks and their spacing.

5. Calculate the Friedman estimate as a rough independent scale check.

6. Group harmonically related candidates:
   3 / 6 / 9 / 12...
   5 / 10 / 15...
   8 / 16...

7. Prefer the smallest fundamental period that explains the strong signals.

8. Test the candidate by recovering its Caesar-style key columns.

9. Recombine the key and verify the resulting plaintext.

The final verification is essential.

A period estimate is useful because it should make the next stage work.

If a proposed period produces incoherent column shifts and poor plaintext while a related divisor succeeds, the divisor is the better model.

That connection between period detection and key recovery is why these methods belong inside a larger Vigenère cryptanalysis workflow, not as isolated numerical tricks.

What this benchmark does not prove

These results are deliberately controlled.

They apply directly to:

one 6,498-letter English literary corpus
standard repeating-key Vigenère
four primitive periods: 3, 5, 8, 12
candidate periods 2 through 20
ciphertext lengths 30 through 800
the exact scoring rules documented above

Change the plaintext language, key periods, candidate range, normalization, Kasiski weighting, IC decision rule, Friedman constants, or autocorrelation interpretation and the percentages can change.

The block counts also decrease as ciphertext length increases.

For example:

30-letter results use 864 ciphertext samples
800-letter results use only 32

The long-length percentages therefore have wider sampling uncertainty.

The benchmark is evidence about method behavior under a fixed setup, not a universal ranking theorem.

The most useful conclusion is not a winner

The four methods do not fail in the same way.

Kasiski needs repeated fragments.

IC can confuse the fundamental period with its multiples.

Autocorrelation often emphasizes harmonic peaks.

Friedman compresses a noisy finite sample into one approximate number.

Those weaknesses are different enough that the methods become more useful together than separately.

In this benchmark, average-column IC was the most consistent way to keep the true period near the top of a candidate list. Kasiski became the strongest method at some medium ciphertext lengths once useful repeats were abundant. Autocorrelation added recurring-spacing evidence, and Friedman supplied a separate whole-text estimate.

So the practical answer to the title question is:

do not ask one method to “prove” the Vigenère key length. Use the methods to generate and cross-check a small harmonic family of plausible periods, then let successful key recovery and plaintext reconstruction decide the fundamental period.

That is more reliable than treating any one maximum, factor, or formula result as the final answer.


Written by Marcus Hale

Editorially reviewed by VigenereDecoder.com editorial team

Written by Marcus Hale

Editorially reviewed by VigenereDecoder.com editorial team

Similar Posts