Search for a tool
Index of Coincidence

Tool to compute coincidence index (IoC) in cryptanalysis, in order to study the probability of finding repeating letters in an encrypted text.

Results

Index of Coincidence -

Tag(s) : Cryptanalysis

Share
Share
dCode and more

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!


Please, check our dCode Discord community for help requests!
NB: for encrypted messages, test our automatic cipher identifier!


Feedback and suggestions are welcome so that dCode offers the best 'Index of Coincidence' tool for free! Thank you!

Index of Coincidence

Cryptanalysis using Index of Coincidence






Answers to Questions (FAQ)

What is the index of coincidence? (Definition)

The index of coincidence (IC or IoC) is an indicator used in cryptanalysis which makes it possible to evaluate the global distribution of letters in an encrypted message for a given alphabet.

A text written in the English language has an index of coincidence of 0.0667. The use of certain ciphers on a message in English will tend to modify this value which can allow them to be recognized. See dCode's cipher identifier.

How to calculate a coincidence index?

Index of coincidence uses the formula:

$$ IC = \sum_{i=A}^{i=Z} \frac{n_{i}(n_{i}-1)}{N(N-1)} $$

with $ n_i $ the number of occurrences of the letter $ i $ in the text and $ N $ the total number of letters.

This index was probably invented by William F. Friedman.

How to use an Index of Coincidence?

For a given ciphered message, the value for the IoC allows to filter the list of ciphering methods to use. It is one of the first cryptanalysis techniques.

If the Index of coincidence is high (close to $ 0.070 $), i.e. similar to plain text, then the message has probably been encrypted using a transposition cipher (letters were shuffled) or a monoalphabetic substitution (a letter can be replaced by only one other).

If the Index of coincidence is low (close to $ 0.0385 $), i.e. similar to a random text, then the message has probably been encrypted using a polyalphabetic cipher (a letter can be replaced by multiple other ones).

The more the coincidence count is low, the more alphabets have been used.

Example: Vigenere cipher with a key of length 4 to 8 letters have an IC of about $ 0.045 \pm 0.005 $

What are values of IC among languages?

For an unencrypted text, coincidence indexes are

English0.0667French0.0778
German0.0762Spanish0.0770
Italian0.0738Russian0.0529

What is a random text?

A text where each letter has the same probability of appearance than another, IC is then of $ 1/N $ (where $ N $ is the number of letters in the alphabet)

Example: $ IC = 0.0385 $ for $ N=26 $

How to calculate a key size from the IC?

In the case where multiple alphabets are used and the key size determines the number of alphabets (as for the Vigenere cipher), by denoting $ n $ the total number of letters in the message and $ m $ the key size, a new coincidence index can be calculated by the formula:

$$ IC = \frac{n-m}{m(n-1)}} \cdot IC_{\text{lang}}} + \frac{n(m-1)}{(n-1)m} \cdot 0.0385 $$

How to code an IC function? (Algorithm)

Examples of codes in programming languages // Python
def ic(self):
num = 0.0
den = 0.0
for val in self.count.values():
i = val
num += i * (i - 1)
den += i
if (den == 0.0):
return 0.0
else:
return num / ( den * (den - 1))

Source code

dCode retains ownership of the "Index of Coincidence" source code. Except explicit open source licence (indicated Creative Commons / free), the "Index of Coincidence" algorithm, the applet or snippet (converter, solver, encryption / decryption, encoding / decoding, ciphering / deciphering, breaker, translator), or the "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.) and all data download, script, or API access for "Index of Coincidence" are not public, same for offline use on PC, mobile, tablet, iPhone or Android app!
Reminder : dCode is free to use.

Cite dCode

The copy-paste of the page "Index of Coincidence" or any of its results, is allowed (even for commercial purposes) as long as you credit dCode!
Exporting results as a .csv or .txt file is free by clicking on the export icon
Cite as source (bibliography):
Index of Coincidence on dCode.fr [online website], retrieved on 2024-11-05, https://www.dcode.fr/index-coincidence

Need Help ?

Please, check our dCode Discord community for help requests!
NB: for encrypted messages, test our automatic cipher identifier!

Questions / Comments

Feedback and suggestions are welcome so that dCode offers the best 'Index of Coincidence' tool for free! Thank you!


https://www.dcode.fr/index-coincidence
© 2024 dCode — El 'kit de herramientas' definitivo para resolver todos los juegos/acertijos/geocaching/CTF.
 
Feedback