加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

暴力破解密码 - C++ 递归方法实现

发布时间:2020-12-15 04:58:01 所属栏目:百科 来源:网络整理
导读:问题描述: ?? ?暴力破解密码 ?? ?假设有一个 4 位字母密码,每位密码是 a~e 之间的小写字母 ?? ?你能否编写一段代码,来暴力破解该密码?(可重复排序) #include #include using std::string; using namespace std; void BreakPassword( string Words,int Pas

问题描述:


?? ?暴力破解密码


?? ?假设有一个 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,不能用#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;

}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读