Например, у меня есть шифрованный текстовый код "KWSVVSYXKSBOKRKBNRKDKXNKNBEXUKBOKDKLKBGRO"
Я использовал некоторые расчеты частотного анализа и начал реверс-инжиниринг, чтобы взломать шифр.
Мой решенный текст шифра
«Новый решенный зашифрованный текст с ключом: AMILLIONAIREAHARDHATANDADRUNKAREATABARWHENT»
Единственная проблема сейчас в том, что я не понимаю, как правильно поставить пробелы между словами, так что это может быть немного больше. Engli sh "A millionaire a hard hat and drunk are..."
Ниже приведен мой Код для взлома шифр
string cipher = "";
int i = 0, alphabet[26] = { 0 }, j, temp;
int n = cipher.length();
// declaring character array
char char_array[343];
// copying the contents of the
// string to char array
strcpy_s(char_array, cipher.c_str());
//print the entire cipher text and ASCII value
//for (int i = 0; i < n; i++)
//{
//cout << char_array[i] << endl;
// cout << "the ASCII value of " << char_array[i] << " is " << int(char_array[i]) << endl;
// }
//Find the most frequent letter in the cipher text
while (char_array[i] != '\0') {
if (char_array[i] >= 'A' && char_array[i] <= 'Z') {
j = char_array[i] - 'A';
++alphabet[j];
}
++i;
}
cout << "Frequency of all alphabets in the string is:" << endl;
for (i = 0; i < 26; i++)
cout << char(i + 'A') << " : " << alphabet[i] << endl;
//end most frequent
cout << endl;
const int N = sizeof(alphabet) / sizeof(int);
for (i = 0; i < 26; i++){
cout << "Most frequent letter is : " << char(distance(alphabet, max_element(alphabet, alphabet + N)) + 'A') << " trying key : " << distance(alphabet, max_element(alphabet, alphabet + N)) << endl;
//cout << alphabet[i] << "Most frequent position of key is trying: " << distance(alphabet, max_element(alphabet, alphabet + N)) << endl;
cout << "New solved cipherr text with key is : " << encrypt(char_array, distance(alphabet, max_element(alphabet, alphabet + N))) << endl << endl;
alphabet[distance(alphabet, max_element(alphabet, alphabet + N))] = 0;
}
string encrypt(string text, int s)
{
string result = "";
// traverse text
for (int i = 0; i<text.length(); i++)
{
// apply transformation to each character
// Encrypt Uppercase letters
result += char(int(text[i] + s - 65) % 26 + 65);
}
// Return the resulting string
return result;
}