Tool to calculate the Index of Coincidence (IC) in cryptanalysis, to assess the probability of letter repetition in the encrypted message.
Index of Coincidence - dCode
Tag(s) : Cryptanalysis
dCode is free and its tools are a valuable help in games, maths, geocaching, puzzles and problems to solve every day!
A suggestion ? a feedback ? a bug ? an idea ? Write to dCode!
The Index of Coincidence (IC or IoC) is a statistical measure used in cryptanalysis to study the distribution of letters in a text. It corresponds to the probability that two distinct positions, chosen at random in the text, contain the same letter.
This measure notably makes it possible to compare the letter distribution of a ciphertext with that of a natural language or a uniformly distributed alphabet. An English text often has an IC close to $ 0.0667 $, while a random text over a uniformly distributed 26-letter alphabet has a theoretical IC close to $ 0.03846 $.
The IC remains unchanged after a bijective monoalphabetic substitution, such as the Caesar cipher. This property helps to find clues about the cipher family used. See the dCode cipher recognition tool.
This measure is historically associated with the cryptanalyst William F. Friedman, who developed it and used it in his cryptanalysis work.
The Index of Coincidence is calculated from the number of occurrences of each letter in the text: $$ IC = \frac{\sum_{i=1}^{q} n_i(n_i-1)}{N(N-1)} $$
where: $ n_i $: number of occurrences of letter $ i $, $ N $: total number of letters, $ q $: number of letters in the alphabet.
For the 26-letter Latin alphabet, the sum runs over the letters from A to Z. Spaces, digits, punctuation marks and other characters are excluded from the calculation.
The numerator counts the ordered pairs of distinct positions containing the same letter. The denominator counts all ordered pairs of distinct positions.
The Index of Coincidence helps to narrow down the list of possible encryption methods for a given message.
— A relatively high IC, close to that of the assumed language, may indicate a transposition or a monoalphabetic substitution.
— A lower IC, close to $ 0.03846 $ for a uniform 26-letter alphabet, may indicate a polyalphabetic cipher, such as Vigenère, which tends to make the overall letter distribution more uniform.
Example: For an English text, a common reference value is $ 0.0667 $. For French, a value close to $ 0.0778 $ is often used.
A low IC does not prove the use of a polyalphabetic cipher. A short text, an atypical distribution or another encryption process can also produce a low value.
The following reference values are commonly used for unencrypted texts:
— French: $ 0.0778 $
— English: $ 0.0667 $
— German: $ 0.0762 $
— Spanish: $ 0.0770 $
— Italian: $ 0.0738 $
— Russian: $ 0.0529 $
These values are approximations, not universal constants. They vary depending on the corpus, vocabulary, style, text length, etc.
A uniform distribution means that each letter of the alphabet has the same probability of appearing. For an alphabet of $ q $ letters, this probability is $ 1/q $. The theoretical IC is then:
$$ IC = \sum_{i=1}^{q}\left(\frac{1}{q}\right)^2 = \frac{1}{q} $$
For a 26-letter alphabet:
$$ IC = \frac{1}{26} \approx 0.03846 $$
The value $ 1/q $ corresponds to the theoretical expected value of the IC when the letters are independent and uniformly distributed.
A strong cipher tends to produce a more uniform letter distribution, close to that of a random text.
A bijective monoalphabetic substitution replaces each letter with another according to a fixed mapping. It changes the names of the letters, but preserves the number of occurrences of each symbol, up to permutation.
As a result, the pairs of positions containing identical letters remain identical after encryption. The Index of Coincidence does not change.
A transposition also preserves the IC since it moves the letters without changing their frequencies.
The Vigenère cipher uses several Caesar-type substitutions, selected successively by the letters of the key, which changes the overall letter distribution of the ciphertext.
To test an assumed key length $ m $, arrange the letters of the ciphertext in $ m $ columns. Each column gathers the letters encrypted with the same shift.
Then calculate the IC of each column, and then their average. If the assumed length is correct, the columns behave approximately like texts encrypted by monoalphabetic substitution and their IC tends to approach that of the original language.
Friedman's method estimates the probable length of a polyalphabetic key from the overall IC of the ciphertext.
For a ciphertext of length $ n $, a key of length $ k $, a reference language IC $ I_{\text{language}} $ and a uniform IC $ I_{\text{uniform}} $, an approximation is:
$$ I \approx \frac{(n-k)I_{\text{language}} + n(k-1)I_{\text{uniform}}}{k(n-1)} $$
Isolating $ k $, the formula becomes:
$$ k \approx \frac{n(I_{\text{language}}-I_{\text{uniform}})}{(I_{\text{language}}-I)+n(I-I_{\text{uniform}})} $$
Example: For a 26-letter English alphabet, $ I_{\text{language}} \approx 0.065 $ and $ I_{\text{uniform}} \approx 0.03846 $ and $$ k \approx \frac{0.02654n}{(0.065-I)+n(I-0.03846)} $$
This formula provides an estimate, not a guaranteed length.
The algorithm consists of adding $ n_i(n_i-1) $ for each letter, then dividing this sum by $ N(N-1) $, where $ N $ represents the total number of letters taken into account.
// Python
def ic(self):
num = 0.0
den = 0
for val in self.count.values():
num += val * (val - 1)
den += val
if den < 2:
return 0.0
return num / (den * (den - 1))
The IC can help identify a language by comparing its value to linguistic references, but it generally does not allow a language to be determined with certainty.
Some languages have fairly similar letter distributions. Moreover, the observed value depends on the length of the text, the subject, the style, etc.
For more reliable identification, combine the IC with individual letter frequencies, groups of two or three letters and other linguistic features. dCode has a language detector.
dCode retains ownership of the "Index of Coincidence" source code. Any algorithm for the "Index of Coincidence" algorithm, applet or snippet or script (converter, solver, encryption / decryption, encoding / decoding, ciphering / deciphering, breaker, translator), or any "Index of Coincidence" functions (calculate, convert, solve, decrypt / encrypt, decipher / cipher, decode / encode, translate) written in any informatic language (Python, Java, PHP, C#, Javascript, Matlab, etc.) or any database download or API access for "Index of Coincidence" or any other element are not public (except explicit open source licence). Same with the download for offline use on PC, mobile, tablet, iPhone or Android app.
Reminder: dCode is an educational and teaching resource, accessible online for free and for everyone.
The content of the page "Index of Coincidence" and its results may be freely copied and reused, including for commercial purposes, provided that dCode.fr is cited as the source (Creative Commons CC-BY free distribution license).
Exporting the results is free and can be done simply by clicking on the export icons ⤓ (.csv or .txt format) or ⧉ (copy and paste).
To cite dCode.fr on another website, use the link:
In a scientific article or book, the recommended bibliographic citation is: Index of Coincidence on dCode.fr [online website], retrieved on 2026-12-06,