Index of Coincidence (IC)The IC method can be used to measure the amount of variation in the frequency of the letters in the cipher: The result is then:
|
Examples
The following are Vigenère ciphers:
- One character key (key="b"): . Try
- Two character key (key="bc"): . Try
- Three character key (key="bcd"): . Try
- Four character key (key="bcde"): . Try
- Five character key (key="bcdef"): . Try
- Six character key (key="bcdefg"): . Try
Theory
The Index of Coincidence (IC) defines the probability of two randomly chosen letters from a cipher having the letter for N letters in the cipher. For example is we want to determine the probablity of two A letters:
\(P(First letter=A) \times P(Second letter=A) = \frac{F_A}{N} \times \frac{F_A-1}{N-1}\)
where \(F_A\) is the number of occurances of the letter A, and N is the number of letters in the cipher. We can now include all the other doubles (BB, CC, and so on) to give:
\(IC=\sum_{i=A}^{Z}\frac{F_i(F_i-1)}{N(N-1)}\)
With a Vigenère Cipher, we can analyse the IC to determine the number of possible characters in the key:
IC= 0.0660 nchars = 1; IC= 0.0520 nchars = 2; IC= 0.0473 nchars = 3; IC= 0.0449 nchars = 4; IC= 0.0435 nchars = 5; IC= 0.0426 nchars = 6; IC= 0.0419 nchars = 7; IC= 0.0414 nchars = 8; IC= 0.0410 nchars = 9; IC= 0.0407 nchars = 10;
A value of 0.0388 (1/26) identifies that the characters are equally probable.
public string prob(string str) { str = str.ToLower(); int [] count = new int [26]; int n = 0; for (int i=0;i<str.Length;i++) { int val = str[i] - 'a'; if (val >= 0 && val <= 25) { count[val] = count[val] + 1; n++; } } double total = 0; for (int i = 0; i < count.Length; i++) { total += count[i] * (count[i]- 1); } total = total/n/(n-1); string result="IC is: "+total.ToString(); int nchars=1; if (total >= 0.0660) nchars = 1; else if (total >= 0.0520) nchars = 2; else if (total >= 0.0473) nchars = 3; else if (total >= 0.0449) nchars = 4; else if (total >= 0.0435) nchars = 5; else if (total >= 0.0426) nchars = 6; else if (total >= 0.0419) nchars = 7; else if (total >= 0.0414) nchars = 8; else if (total >= 0.0410) nchars = 9; else if (total >= 0.0407) nchars = 10; else nchars = 0; result += "\nPredicted characters in password is: " + nchars.ToString(); return (result); }