密码破解程序返回的\u父\u代理为0xCCCC 我试图用C++编写一个蛮力密码破解器,但是下面的代码总是给我这个错误(未处理的异常抛出:读访问违例)。 _父\u代理为0xCCCC) 我相信错误在generate函数中,因为代码运行时注释掉了它。该代码也不完整,但它应该运行的sha256饼干,任何帮助将不胜感激 #include <iostream> #include <string> #include "sha256.h" //prototype functions void Crack(); std::string Generate(unsigned int length, std::string s); bool Compare(std::string sha256, std::string sha512, std::string md5, std::string PassHash); const char PassChar[61] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '1' , '2', '3', '4', '5', '6', '7', '8', '9' }; int main() { std::cout << "Cracking Password \n"; Crack(); return 0; } void Crack() { unsigned int stringlength = 1; const std::string PassHash = "BC98BB50E8094B2AC3CEB90BA2512587C0513CD294A07EFCFDCF467198DA6266"; while (stringlength < 9) { //increases password length up to 8 characters std::string PassAttempt = Generate(stringlength, ""); //Hashes password attempts std::string Sha256Attempt = ""; picosha2::hash256_hex_string(PassAttempt, Sha256Attempt); std::string Sha512Attempt = ""; std::string Md5Attempt = ""; //Checks for a correct hash bool Collision = Compare(Sha256Attempt, Sha512Attempt, Md5Attempt, PassHash); if (Collision = true) { std::cout << "Password Cracked! \n Password = " << PassAttempt; return; } stringlength++; } std::cout << "Password Not Cracked: password may be too long, max 8 chars"; return; } std::string Generate(unsigned int length, std::string s) { if (length == 0) // when length has been reached { //std::cout << s << "\n"; // print it out return s; } for (unsigned int i = 0; i < 61; i++) { // Call generate again until string has reached it's length std::string appended = s + PassChar[i]; Generate(length - 1, appended); } } bool Compare(std::string sha256, std::string sha512, std::string md5, std::string PassHash) { bool Collision = false; if (PassHash.compare(sha256)) { Collision = true; } if (PassHash.compare(sha512)) { Collision = true; } if (PassHash.compare(md5)) { Collision = true; } return Collision; } #包括 #包括 #包括“sha256.h” //原型函数 空隙裂缝(); std::string Generate(无符号整数长度,std::string s); bool比较(std::string sha256、std::string sha512、std::string md5、std::string PassHash); const char PassChar[61]= { ‘a’、‘b’、‘c’、‘d’、‘e’、‘f’、‘g’, ‘h’、‘i’、‘j’、‘k’、‘l’、‘m’、‘n’, ‘o’、‘p’、‘q’、‘r’、‘s’、‘t’、‘u’, “v”、“w”、“x”、“y”、“z”, ‘A’、‘B’、‘C’、‘D’、‘E’、‘F’、‘G’, ‘H’、‘I’、‘J’、‘K’、‘L’、‘M’、‘N’, ‘O’、‘P’、‘Q’、‘R’、‘S’、‘T’、‘U’, “V”、“W”、“X”、“Y”、“Z”, '1' , '2', '3', '4', '5', '6', '7', '8', '9' }; int main() { std::cout

密码破解程序返回的\u父\u代理为0xCCCC 我试图用C++编写一个蛮力密码破解器,但是下面的代码总是给我这个错误(未处理的异常抛出:读访问违例)。 _父\u代理为0xCCCC) 我相信错误在generate函数中,因为代码运行时注释掉了它。该代码也不完整,但它应该运行的sha256饼干,任何帮助将不胜感激 #include <iostream> #include <string> #include "sha256.h" //prototype functions void Crack(); std::string Generate(unsigned int length, std::string s); bool Compare(std::string sha256, std::string sha512, std::string md5, std::string PassHash); const char PassChar[61] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '1' , '2', '3', '4', '5', '6', '7', '8', '9' }; int main() { std::cout << "Cracking Password \n"; Crack(); return 0; } void Crack() { unsigned int stringlength = 1; const std::string PassHash = "BC98BB50E8094B2AC3CEB90BA2512587C0513CD294A07EFCFDCF467198DA6266"; while (stringlength < 9) { //increases password length up to 8 characters std::string PassAttempt = Generate(stringlength, ""); //Hashes password attempts std::string Sha256Attempt = ""; picosha2::hash256_hex_string(PassAttempt, Sha256Attempt); std::string Sha512Attempt = ""; std::string Md5Attempt = ""; //Checks for a correct hash bool Collision = Compare(Sha256Attempt, Sha512Attempt, Md5Attempt, PassHash); if (Collision = true) { std::cout << "Password Cracked! \n Password = " << PassAttempt; return; } stringlength++; } std::cout << "Password Not Cracked: password may be too long, max 8 chars"; return; } std::string Generate(unsigned int length, std::string s) { if (length == 0) // when length has been reached { //std::cout << s << "\n"; // print it out return s; } for (unsigned int i = 0; i < 61; i++) { // Call generate again until string has reached it's length std::string appended = s + PassChar[i]; Generate(length - 1, appended); } } bool Compare(std::string sha256, std::string sha512, std::string md5, std::string PassHash) { bool Collision = false; if (PassHash.compare(sha256)) { Collision = true; } if (PassHash.compare(sha512)) { Collision = true; } if (PassHash.compare(md5)) { Collision = true; } return Collision; } #包括 #包括 #包括“sha256.h” //原型函数 空隙裂缝(); std::string Generate(无符号整数长度,std::string s); bool比较(std::string sha256、std::string sha512、std::string md5、std::string PassHash); const char PassChar[61]= { ‘a’、‘b’、‘c’、‘d’、‘e’、‘f’、‘g’, ‘h’、‘i’、‘j’、‘k’、‘l’、‘m’、‘n’, ‘o’、‘p’、‘q’、‘r’、‘s’、‘t’、‘u’, “v”、“w”、“x”、“y”、“z”, ‘A’、‘B’、‘C’、‘D’、‘E’、‘F’、‘G’, ‘H’、‘I’、‘J’、‘K’、‘L’、‘M’、‘N’, ‘O’、‘P’、‘Q’、‘R’、‘S’、‘T’、‘U’, “V”、“W”、“X”、“Y”、“Z”, '1' , '2', '3', '4', '5', '6', '7', '8', '9' }; int main() { std::cout,c++,C++,您的代码具有未定义的行为: foo.cc: In function ‘std::__cxx11::string Generate(unsigned int, std::__cxx11::string)’: foo.cc:87:1: warning: control reaches end of non-void function [-Wreturn-type] } ^ 在编译器中打开编译器警告并读取它们 一旦您这样做了,并且看到您的代码没有达到预期效果,您就会想到为什么Generate不能

您的代码具有未定义的行为:

foo.cc: In function ‘std::__cxx11::string Generate(unsigned int, std::__cxx11::string)’:
foo.cc:87:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
在编译器中打开编译器警告并读取它们


一旦您这样做了,并且看到您的代码没有达到预期效果,您就会想到为什么Generate不能生成所有可能的密码并返回它们。

“if(Collision=true)”应该是“if(Collision=true)”“。但主要是学习如何使用调试器。调试器没有达到那个程度,所以我错过了一个不幸的例子:Visual Studio在调试模式下用0xCCCC填充未初始化的变量。它甚至在消息中命名变量……请注意,当字符串相等时返回0(false)。谢谢,在我的匆忙中,我显然弄乱了代码的逻辑