StringTools - Maple Programming Help

Home : Support : Online Help : Programming : Names and Strings : StringTools Package : Statistics : StringTools/IndexOfCoincidence

StringTools

 IndexOfCoincidence
 compute the arithmetic mean of the characters (bytes) in a string

 Calling Sequence IndexOfCoincidence( s )

Parameters

 s - Maple string

Description

 • The IndexOfCoincidence(s) command returns the index of coincidence of a sample s of text. It can be defined by the formula $\frac{\mathrm{add}\left({f}_{\mathrm{ch}}\left({f}_{\mathrm{ch}}-1\right),\mathrm{ch}=\mathrm{Ι}\left(1..255\right)\right)}{n\left(n-1\right)}$ where, for each character ch, ${f}_{\mathrm{ch}}$ 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.

Examples

 > $\mathrm{with}\left(\mathrm{StringTools}\right):$
 > $\mathrm{IndexOfCoincidence}\left("foo"\right)$
 ${0.333333333333333315}$ (1)
 > $\mathrm{IndexOfCoincidence}\left(\mathrm{Random}\left(100000\right)\right)$
 ${0.00392208322083220824}$ (2)