T

Text Machine

Powerful text tools, in your browser

Index of Coincidence Calculator

Measure how lumpy a text's letter distribution is, and read the key length straight off the column table.

Try:

Text

Paste some text to measure it. The Caesar and Vigenere samples are the same passage as the English one, so you can watch what each kind of cipher does to the number.

How to use Index of Coincidence Calculator

  1. 1

    Paste the text

    Drop plaintext or ciphertext into the box. Only A-Z letters take part; case, spaces, digits and punctuation are ignored, so formatting cannot move the number.

  2. 2

    Read the index

    The raw IC is the probability that two letters drawn at random are the same letter. The normalised figure is that value against a uniform alphabet, where 1.00 is random and about 1.73 is English.

  3. 3

    Decide what kind of cipher you have

    Around 0.066 means the letter distribution is intact, so the text is plaintext or a simple substitution. Around 0.038 means it has been flattened, which points at a repeating-key cipher.

  4. 4

    Find the key length in the column table

    If the text looks polyalphabetic, look for the shortest length whose column IC climbs back towards 0.066. That is the key length, and it is the number the Vigenere solver needs.

The Index of Coincidence, explained

One number, one question

The Index of Coincidence answers a narrow question: if you reach into a text twice and pull out a letter each time, how often do you get the same letter twice? For a bag of 26 equally common letters the answer is 1 in 26, about 0.0385. For English it is nearly twice that, about 0.066, because English is not an even bag. E, T, A and O do an enormous amount of the work and J, Q, X and Z barely turn up.

That gap is the whole of the statistic's usefulness. It survives relabelling: if you swap every A for a Q and every Q for an A, the counts move but the lumpiness does not, so the index is unchanged. It does not survive being spread across several alphabets, which is exactly what a repeating-key cipher does.

What it can and cannot tell you

An IC near 0.066 says the letter distribution is intact. That covers ordinary plaintext, a Caesar shift, an Atbash mirror and any simple substitution cipher, and it is why a monoalphabetic cipher is broken with frequency analysis rather than with this number.

An IC near 0.038 says the distribution has been flattened. Something is mapping one plaintext letter to several ciphertext letters, which is the signature of Vigenere and its relatives, or of a genuinely random string.

A reading in between usually means the text is too short rather than that the cipher is unusual. Under about a hundred letters the index bounces around enough to be misleading, and under about three hundred it is worth treating as a hint rather than a verdict.

The column table is the part that does the work

The single number for the whole text tells you the kind of cipher. Finding the key length takes a second step, and it is the step most calculators leave out.

Take the letters and deal them into L piles: positions 1, L+1, 2L+1 into the first pile, positions 2, L+2 into the second, and so on. If L is the real key length then every letter in a pile was shifted by the same key letter, so that pile is a Caesar cipher of English and keeps English's lumpiness. If L is wrong, each pile mixes letters that were shifted by different amounts and comes out flat.

So the column IC, averaged across the piles, rises at the true key length and at every multiple of it. Reading down the table for the first length that jumps is the classical way to find a Vigenere key length, and it is more reliable than the Friedman formula on real texts.

Where to go next

If the column table points at a length, Kasiski examination is the natural second opinion: it works from the distances between repeated sequences instead of from letter statistics, so it fails in different places. Two independent methods agreeing on the same number is much stronger evidence than either alone.

Once you are confident about the length, the Vigenere solver will take the ciphertext, split it into that many columns, break each one as a Caesar cipher and hand back the keyword and the plaintext.

Frequently asked questions

What is the Index of Coincidence?
It is the probability that two letters picked at random from a text turn out to be the same letter. Written out, it is the sum of n(n-1) over each letter's count, divided by N(N-1) for the whole text. English comes out around 0.066 because a few letters do most of the work; a uniform random alphabet comes out at 1/26, or about 0.0385.
Why does my number differ from another calculator?
Almost always because of normalisation. Some tools report the raw probability and some multiply it by 26, so the same text reads as either 0.0667 or 1.73. Both figures are shown here. The other common cause is that a tool counted spaces or digits as characters; this one counts only A-Z letters.
How does the Index of Coincidence find a key length?
It does not, on its own. What finds the length is splitting the ciphertext into L columns and measuring each column separately. At the true L, every column was enciphered with one repeating shift, so each column is a Caesar cipher of English and keeps English's IC. At a wrong L the columns are mixtures and stay flat. The column table shows every candidate side by side.
What is the Friedman estimate and should I trust it?
It is a 1922 formula that turns one IC into an approximate key length. It is useful as a sanity check next to the column table and it is wrong often enough that it should never be used alone, especially on short texts. A dash appears when your text is already as lumpy as plaintext, or too short to have an IC at all. The formula assumes a repeating key has flattened the text, so outside that range there is nothing to estimate and any number would be invented.
Why do 5 and 10 and 15 all score well?
Because a split into 10 columns is a split of the real 5 columns into halves, so each half still keeps its single shift. Every multiple of the true length inherits its score. The shortest member of the family is the answer, which is why the suggestion list drops the multiples.
Can it tell me what language a text is in?
Only very roughly. The comparison table shows where your text sits against published figures, but several languages have similar values and a short sample moves by more than the gaps between them. Use it to separate natural language from random-looking text, not to pick between French and Spanish.
Does my text leave my browser?
No. The whole calculation runs in the page. Nothing is uploaded, logged or stored anywhere.

Related tools

Keep going with these handy tools

Kasiski Examination

Vigenère Solver

Frequency Analysis

Cipher Identifier

Substitution Cipher Solver

Unix Timestamp Converter