【发布时间】:2018-04-21 20:28:06
【问题描述】:
我想用 affine_algorithm 解密消息,但从一开始就不知道密钥,我需要暴力破解它们以找到正确的组合。在下面的代码中,解密的消息是不正确的,为了理解它们,它们没有任何意义。我认为仿射方程有问题,我看到了一些其他带有a_inverse 的代码,但我不知道如何在不知道密钥的情况下进行暴力破解。
#include<iostream>
#include<string.h>
#include<stdlib.h>
#include <string>
#include <fstream>
using namespace std;
int main(int argc, char **argv)
{
ifstream myfile("C:\\encr_affine.txt");
string Ciphertext;
while (myfile>>Ciphertext)
{
getline(myfile, Ciphertext);
}
for (int b = 1; b <= 25; b++)
{
for (int a = 1; a <= 25; a = a + 2)
{
if (a == 13)
a = 15;
string Msg = "";
for (int i = 0; i < Ciphertext.length(); i++)
{
if (Ciphertext[i] != ' ')
Msg = Msg + (char)(((a * ((Ciphertext[i] - 'A' + b)) % 26)) + 'A');
else
Msg += Ciphertext[i];
}
cout << "\n Key is : " << a << ", " << b << endl;
cout << "Decr. message is : " << Msg << endl;
}
}
myfile.close();
}
【问题讨论】:
标签: c++ encryption brute-force