今天在看hash函数对于数字或字符进行加密的知识,有感而发就写了一个C++破解6位数数字密码的程序,程序很简单,也很容易理解,并给也给出了对于不同密码所需要破解的时间。好了,废话不多少,直接贴程序:
#include <iostream>
#include<time.h>
using namespace std;
int main(){
int a,b,c,d,e,f,i=0;
int password[6];
cout<<"请输入6位数密码:"<<endl;
for (a=0;a<6;a++)
cin>>password[a];
clock_t start_time=clock();
{
for (a=0;a<10;a++)
{for (b=0;b<10;b++)
{for (c=0;c<10;c++)
{for (d=0;d<10;d++)
{for (e=0;e<10;e++)
{for (f=0;f<10;f++)
if (password[0]==a&&password[1]==b&&password[2]==c&&password[3]==d&&password[0]==e&&password[0]==f)
{cout<<"已找到密码:";i=1;break;}
if (i==1) break;}
if (i==1) break;}
if (i==1) break;}
if (i==1) break;}
if (i==1) break;}
}
clock_t end_time=clock();
if (i==1)
cout<<a<<b<<c<<d<<e<<f<<endl;
else cout<<"没有找到密码"<<endl;
cout<< "Running time is: "<<static_cast<double>(end_time-start_time)/CLOCKS_PER_SEC*1000<<"ms"<<endl;//输出运行时间
system("pause");
return 0;
}