/* ========================================================================== */ /* */ /* myVig.cpp */ /* Brian Marsh */ /* */ /* Simple vigenere's cipher program */ /* */ /* ========================================================================== */ #include #include #include #include #include using namespace std; void getFreq( int keyLen, int offsetBy, char cipher[], vector& freq); double index(string cipherText, int colSize, int offset); void keyLength(string cipher); int main() { string cipher; int len; double ic; cin >> cipher; keyLength(cipher); return 0; } //*/ //BLOCK COMMENT void keyLength(string cipher){ char cipherArray[cipher.size()]; strncpy(cipherArray, cipher.c_str(),cipher.size()); int guess = 2; int largestKey = (int)sqrt(cipher.size()); //cout <<"outer for begins\n"; for (int keyLen = 2; keyLen <= largestKey; keyLen++) { //cout <<"inner for begins\n"; for (int off = 0; off < keyLen; off++) { //cout <<"before index function\n"; double indexVal = index(cipher, keyLen, off); //cout << "Key Len = "< holding; vector freq; //cout <<"before getFreq\n"; getFreq(colSize, offset, cipherArray, freq); //cout <<"afterGetFreq\n"; holding = freq; for (int i = 0; i < 26; i++){ ic = ic + holding[i]*(holding[i]-1); len = len + holding[i]; } return ic/(len*(len-1)); } //*/ //END BLOCK COMMENT //*/ //BLOCK COMMENT void getFreq( int keyLen, int offsetBy, char cipher[], vector& freq){ //cout <<"in getFreq Function\n"; vector fillMe(26); //cout <<"before For \n"; for (int i = offsetBy; i < sizeof(cipher); i+=keyLen){ //cout <<"getFreq for loop. i = "<