暴力破解密码 - C++ 递归方法实现
问题描述: ?? ?暴力破解密码 ?? ?假设有一个 4 位字母密码,每位密码是 a~e 之间的小写字母 ?? ?你能否编写一段代码,来暴力破解该密码?(可重复排序) #include #include using std::string; using namespace std; void BreakPassword( string Words,int PasswordLen,string result) { ?? ?if (result.length() == PasswordLen) ?? ?{ ?? ??? ?//C++中string类型不能直接输出,需加头问题#include ?? ??? ?cout << result << " ? ?"; ?? ??? ?return; ?? ?} ?? ?for (int i = 0; i < Words.length(); ++i) ?? ?{ ?? ??? ?string newResult = result; ?? ??? ?newResult.insert( newResult.end(),Words[i] ); ?? ??? ?BreakPassword(Words,PasswordLen,newResult); ?? ?} } int _tmain(int argc,_TCHAR* argv[]) { ?? ?int passwordLen = 4; ?? ?string words("abcde"); ?? ?string result = ""; ?? ? ?? ?BreakPassword(words,passwordLen,result); ?? ?return 0; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |