How to use the kasiski and index of coincidence analyzer
- Paste the ciphertext. Only the letters A to Z are used.
- Set the length of repeats to search for and the longest key length to try.
- Read the key length with the highest index of coincidence and the whole-text index.
- Use the repeat table to see the gaps and which key lengths divide them.
Formula
Index of coincidence IC = sum of n(i) x (n(i) - 1) / (N x (N - 1)) over the 26 letters
For a key length k, split the text into k columns and average the IC of the columns
Kasiski: find repeated groups of letters, take the gaps between repeats and count the common factors
English text has an IC near 0.067. Random letters have an IC near 0.038, which is 1/26.
A short message with the key LEMON
The sample is a real Vigenere ciphertext made with the key LEMON, which has 5 letters. The whole-text IC is 0.0407, close to random, which suggests more than one alphabet is in use. Splitting the text into 5 columns raises the average IC to 0.0878, the highest of any length tried, so the key length is 5.
The tool also found 20 repeats of 3 letters. The first, XTS, appears at positions 6, 71, 101 and 121, with gaps of 65, 30 and 20. All of these are multiples of 5, and 5 is the most common factor among the gaps.
Two ways to find the key length
A Vigenere cipher shifts each letter by a letter of a repeating key. If the same piece of text lines up with the same part of the key, it gives the same ciphertext. The distance between two such repeats must then be a multiple of the key length, which is the Kasiski test. The index of coincidence takes a different view. When the text is split by the correct key length, each column has been shifted by a single letter and behaves like plain language, so its IC rises toward 0.067.
The two methods support each other. When both point to the same length, the key is probably that long and each column can be solved like a simple shift cipher.
Limits
Short messages give noisy results, and some repeats are chance. A key that is almost as long as the message hides the pattern. This tool finds a length and does not recover the key. To encrypt and decrypt with a known key use the Vigenere Cipher Tool, and for the same idea with bytes the Repeating Key XOR Tool. The Word Frequency Counter and the Shannon Entropy Calculator give other views of text statistics.
Assumptions and limits
- The text is a polyalphabetic cipher with a repeating key, written in 26 letters.
- Spaces, digits and punctuation are ignored.
- The sample is an example. Use your own ciphertext.
- Everything is calculated in your browser and nothing is uploaded.
Frequently asked questions
What IC value should I expect?
About 0.067 for English text, 0.038 for random letters. The value for a good key length falls between those.
Why try a range of key lengths?
Multiples of the true length also score high, so the tool lists the average IC for each length and you pick the smallest that stands out.
Does it work on a simple shift cipher?
A single shift keeps the IC of the language, near 0.067, so the whole-text value alone shows that it is not polyalphabetic.
Does the tool find the key?
No. It estimates the key length. Once you have that, each column can be attacked with letter frequencies.