1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
string Senator::getDecryption(string &cipher)
{
Albahri albahri(*this);
int shiftAmount = 0;
string shiftedCipher;
//from wikipedia
char mostFreq[26] = { 'E', 'T', 'A', 'O', 'I', 'N', 'S', 'H', 'R', 'D',
'L', 'C', 'U', 'M', 'W', 'F', 'G', 'Y', 'P', 'B',
'V', 'K', 'J', 'X', 'Q', 'Z' };
//find amount
for (int i = 0; i < 26; i++)
{
shiftAmount = albahri.mostFreqLetter(cipher) - mostFreq[i];
shiftedCipher = albahri.ShiftedCipher(cipher, shiftAmount);
cout << "frequent letter being checked is: " << mostFreq[i] << endl;
if (albahri.fillDictionary(shiftedCipher))
{
cout << "shifted cipher is: " << shiftedCipher << endl;
cout << "cipher is still: " << cipher << endl;
cout << "we found it! the cipher is: " << shiftedCipher << endl;
break;
}
else
{
cout << "shifted cipher is: " << shiftedCipher << endl;
cout << "cipher is still: " << cipher << endl;
cout << "we couldn't decipher the word" << endl << endl;
}
}
return shiftedCipher;
}
|