1001Ferramentas
🔍 Security

Kasiski Test for Vigenère

Find repeated trigrams in ciphertext, compute GCD of distances and suggest the Vigenère key length.

Kasiski: finding the key length by counting distances

Vigenère held out for three centuries for a simple reason: with the key changing the alphabet on every letter, frequency analysis finds nothing. Friedrich Kasiski published in 1863 the observation that brought it down. If a stretch of plaintext repeats and lands aligned with the same part of the key, it produces the same ciphertext stretch — and the distance between the two occurrences is a multiple of the key length.

Paste the ciphertext and the page looks for repeated trigrams, lists the distances between their occurrences and computes the greatest common divisor. That divisor is the best estimate of the key length. With the length in hand the cipher falls apart: separating the letters into positions spaced by that length, each group was enciphered with a single alphabet, and each group yields to ordinary frequency analysis.

The method needs text to work — a few hundred characters at least, because trigram repetitions are rare in little material. It also produces false positives: trigrams repeating by chance, with no key alignment, contaminate the divisor. So it pays to look at the distances one by one rather than accepting the divisor blindly, discarding the ones that stand out.

Frequently asked questions

Why trigrams and not letter pairs?
Because pairs repeat by chance far too often and flood the analysis with noise. Trigrams are already rare enough that a repetition suggests genuine alignment with the key, while still common enough to appear in text of moderate length.
Is there another way to find the key length?
There is, and it tends to be more robust: the index of coincidence, proposed by Friedman. It measures how closely the letter distribution matches the language's for each candidate key length, and does not depend on repetitions turning up. In practice both are used — when they agree, confidence is high.
Does it work on Vigenère with a key as long as the text?
No. If the key is as long as the message and never repeats, there is no periodic alignment and the method has nothing to lean on. That is the one-time pad, which with a truly random key is the only system with proven security.

Related Tools