StringTools
IndexOfCoincidence
compute the arithmetic mean of the characters (bytes) in a string
Calling Sequence
Parameters
Description
Examples
IndexOfCoincidence( s )
s
-
Maple string
The IndexOfCoincidence(s) command returns the index of coincidence of a sample s of text. It can be defined by the formula add⁡fch⁢fch−1,ch=Ι⁡1..255n⁢n−1 where, for each character ch, fch is the frequency with which ch occurs in the input string.
The index of coincidence is returned as a floating point number, and the calculation is carried out at hardware precision.
In elementary cryptanalysis, the index of coincidence is often used in conjunction with the Kasiski test to attempt to determine the number of alphabets used in a polyalphabetic substitution cipher.
All of the StringTools package commands treat strings as (null-terminated) sequences of 8-bit (ASCII) characters. Thus, there is no support for multibyte character encodings, such as unicode encodings.
with⁡StringTools:
IndexOfCoincidence⁡foo
0.333333333333333315
IndexOfCoincidence⁡Random⁡100000
0.00392208322083220824
See Also
string
StringTools[Kasiski]
Download Help Document