我的解密哪里出了问题
Where am i going wrong with my decryption
我正在尝试解密一个我不知道密钥的.bin文件,以回答我们在课堂上遇到的这个问题:8) 假设您不知道在6)中使用的"key"的值。你还能解密加密文件吗?如果是这样的话,编写一个程序来实现这一点。(没有分数,这个只是为了好玩!)证明
int main(int argc, char* argv[]) {
uint8_t c, key = 0, uintOutput = 0;
string Encrypted, everything[255];
char b, charOutput;
int x = 0;
while ((b = getchar()) != EOF) {
Encrypted = Encrypted + b; //read in chars from file and add them to a string (still encrypted)
}
我试过几种方法,我真的认为这一种会奏效。
for (int i = 0; i < Encrypted.length(); i++) //for the length of the encrypted string
{
x = 0; //resets the string it is entering into; Array position 0
for (key = 0; key < 255; key++) //key used must be a lowercase letter
{
c = (uint8_t)Encrypted[x]; //convert char 'x' of encrypted string to a byte
uintOutput = (c ^ key); //XOR with current key guess
charOutput = (char)uintOutput; //convert byte back to char again
everything[x] = everything[x] + charOutput; //add xor'd char to currently selected string
x++; //move to next array position; to next string
}
}
其中,everything是字符串数组-everything[255],key是表示加密/解密密钥的字节。
for (int y = 0; y < (255* Encrypted.length()); y++) //print out for number of possibilities
{
cout << everything[y] << endl << endl;
}
return 0;
}为了运行程序,我使用了一个带有文件重定向的.bat文件,在我的情况下,bat文件包含以下内容:program.exe < EncryptedText.bin >> ciphertext.bin
其中EncryptedText.bin是使用未知密钥加密的文件,而密文.bin是输出解密文本的位置。
该程序构建良好,文件重定向也很好,因为我在另一个程序中使用过它,该程序猜测密钥只有一个字符,而不是不受限制的长度。
我遇到的主要问题是当我运行.bat文件时弹出一条错误消息
调试断言失败!
程序:C:\WINDOWS\SYSTEM32\MSVCP140D.ddl
文件i:\microsoft visual studio\vc\include\xstring
线路:1681
表达式:字符串下标超出范围
(此处重试等)
我真的很感激对此有任何见解,我只是看不出我哪里出了问题,我已经在这个问题上纠缠了几个小时
以下是您出错的地方(只有相关的代码行):
for (int i = 0; i < Encrypted.length(); i++)
{
x = 0;
for (key = 0; key < 255; key++)
{
c = (uint8_t)Encrypted[x];
// Some code here that's not relevant
x++;
}
}
很明显,您的代码将尝试通过Encrypted[254]
访问Encrypted[0]
,因此除非您的Encrypted
字符串长254个字符,否则这将导致未定义的行为。
它看起来真的像这里:
for (int y = 0; y < (255* Encrypted.length()); y++)
索引超出CCD_ 5。
- 警告处理为错误这里有什么问题
- 最小硬币更换问题(自上而下方法)
- 为"adjacent"变量赋值时出现问题
- 我的神经网络不起作用 [XOR 问题]
- 在Ubuntu 16.04上安装Cilk时出现问题
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 编译包含字符串的代码时遇到问题
- Project Euler问题4的错误解决方案
- 问题:什么是QAbstractItemView::NoEditTriggers的反面
- 在编译C++代码(具有dlib和opencv)到WASM时面临问题
- 在进程中对同一管道进行读取和写入时C++管道出现问题
- 静态数据成员的问题-修复链接错误会导致编译器错误
- 凯撒密码在C++中无法正确解密的问题
- C ++中的加密和PHP中的解密有什么问题
- Mupdf加密解密问题
- rijndael算法-解密问题
- 关于我的解密程序,有两个问题,C++有问题
- C++XOR解密问题
- 这个加密/解密算法哪里出了问题
- 我的解密哪里出了问题