I'm developing an algorithm that takes in a vigenere cipher and produces the key length automatically. However, I'm having trouble understanding how to detect the key length when there are multiple large index of coincidences.
For example, given this cipher:
vptnvffuntshtarptymjwzirappljmhhqvsubwlzzygvtyitarptyiougxiuydtgzhhvvmum
shwkzgstfmekvmpkswdgbilvjljmglmjfqwioiivknulvvfemioiemojtywdsajtwmtcgluy
sdsumfbieugmvalvxkjduetukatymvkqzhvqvgvptytjwwldyeevquhlulwpkt
My algorithm produces the following indexes of coincidences for each possible key length:
KL IoC
1 0.04494435235614492 --> 4%
2 0.0457833618884447 --> 5%
3 0.04358853643122834 --> 4%
4 0.04749622926093514 --> 5%
5 0.039361207897793266 --> 4%
6 0.04714370596723538 --> 5%
7 0.09099225897255454 --> 9%
8 0.04618589743589745 --> 5%
9 0.04078047556308426 --> 4%
10 0.03611528822055138 --> 7%
11 0.04916033399005535 --> 5%
12 0.05126633986928104 --> 5%
13 0.04468864468864469 --> 4%
14 0.09884877027734174 --> 10%
15 0.033455433455433455 --> 3%
16 0.03962703962703963 --> 4%
17 0.04305498423145482 --> 4%
18 0.04747474747474748 --> 5%
19 0.030303030303030304 --> 3%
20 0.03222222222222222 --> 3%
21 0.082010582010582 --> 8%
22 0.0436868686868687 --> 4%
23 0.03260869565217391 --> 3%
24 0.05158730158730159 --> 5%
25 0.03666666666666666 --> 4%
26 0.04441391941391941 --> 4%
27 0.03791887125220458 --> 4%
28 0.1058673469387755 --> 11%
The correct key length for this cipher is indeed "7", but why is it not 14, 21, or 28? Their IoC is higher after all? What can I do within my algorithm to make it produce 7 as the key length rather than 14, 21, or 28 (or vice versa)?