# Vigenère cipher frequency analysis not working [closed]

I'm writing a C++ program to use the Kasiski method to crack the Vigenère cipher. I'm testing it with a bit of Shakespeare encrypted with the key ABCDEFGHIJKL. It can find the key length, (even when I changed it), but when I started using frequency analysis, the poem's frequency doesn't seem to fit with normal english; in some lines, T occurs twice as much as E when I try to do frequency analysis.

cout << "The key length is most likely " << len << "." << endl;

for (int i = 0; i < len; i ++) {
string m;
int j = 0;
do {
m += ciphertext[i + len * j];
} while (i + len * j++ < length(ciphertext));
cout << m << endl;
}


So I input

UQEITXUWCDZNFVKEYOZBQOBGFUWMTTDPNDSQSVLWSUITNBTZUJHQNTKBXCFRGGUXMKZTRXREBPG
EWXVEBYQAVVUELKVCBPZDUWQITXAWCKVQBTPWFMHQWCEMTGDSKZYWDLWQTCQHGEVXYYDUOIHRIZ
OMVDZPJGWSXRLMYXZYPTHESJIGJCWQFRWSXGFENOYPUJHLJGYBJMSQBPGXMKAPXEDMOFQEYAYIU
QRHVHNHVLOEAETHERGFMCRPDFUWLJXBJOYCUOVKEYYSMNZZREGDXMCOICNCQBOVQFEJWVOHTFPZ
IMGCMBRFRGNHHTLMBQSDYPTWEQIVQUWFEUILZJAZXJEDQUJHVJYAPNBPEQGFXYNHBVKVQTEDPFS
PBHYQEPNRRLRPNNPZDXJRATASLKOLDUJHAMOWAJXOEDQURXUMBRWPFIGRTUXLABYCEXTRRLZOMY
BZGEODRXIVVCEXQMAWLJVHVPCZREGVTNYLLUYGQUJHPFCZLNVLKUJHMSYVTNXNQPHRJKOJMJXOF
IGVTZXUACRLFQCWMJTAUNBTFPHWLJAUEXBETZVDOJYDPNXSQIKPWJRMURQSFIKVUZOLBDCXMLGZ
MYNHJJBPNPFNMSCOWFYFXEVKIXKMIANPXTDHEWZVOAEYFBPGWBKHBDXOQSCZIFXFTRPPNVVWLFZ
APNNCQBFRJXUTMCRTZHCIXJXKMJDSFIGXRIOZKXFPDFFFSZTAZHPCANYKSXKIWDBYZPVUEAKSTN
BCQUWURXVBHIVPEUJHANRSIWNXMLGVYXXHBQOCNFCUXMUZMRVWEXGKEAKAPJXQXZVRSYNLZBDSM
UYHOSUDVXDZRUJXWHUUALSPZDGGSJYTITONAXCUHXUMCBKWXBPGXMAZBQOYMUKYIMALWOBPEPNX
XNUUQBCTOLNLIIULZFSETUJHTFRLKJCEAGVKSZMOBJXOQOVH


and it finds the length 12 and it gets the 1st, 13th, 25th, etc. characters, and it correctly gives

UFFSUGBVUBTTOJPFUBODJDEXPQEFOEBFGPUUQTPXUDIXEMEUUPIQPZIILPETBSVBHIFNPUULFXZUUDXBUPL
UGO


But when I analyze the string separately, there are almost twice as more Us (correspond to T) than Fs (correspond to E). I think I did something wrong here…

• Maybe just run the frequency analysis on the actual text? It is possible, that this part of text does not fit the standard language distribution (don't forget, it takes every 12th symbol). And did you encounter similar problems with the other ensembles of characters (chars at 2,14,26,... ; 3,15,27,...;...)? – tylo Jun 9 '15 at 11:57
• @tylo It's not only that part of text. Out of the 11 sequences generated from the square, 4-5 of them don't have the right frequencies... – raumaan kidwai Jun 9 '15 at 12:01
• Here goes testing with key length 15... – raumaan kidwai Jun 9 '15 at 12:02
• For this amount of text that's entirely possible. The larger the text, the better the statistics (unless it is off on purpose, e.g. poems could do that). – Maarten Bodewes Jun 9 '15 at 18:29
• Since no one is talking like Shakespeare today, there are differences in language characteristics. For example, in his works the word thou (and its different cases, e.g. thee, thy) is used quite a lot, but in any modern english this would be you instead => leads to an increase in t and a decrease in y – tylo Jun 10 '15 at 11:24