生成所有可能的单词组合,以查找任意长度的密码,使用小写字母(a 到 z)
这段代码在 Intel Core i3、i5、i7 处理器系列上每秒打印超过 500 个组合(如果超过 500 个)...
这段代码可以被修改以使其更快,你只需要做的是创建一个文件,而不是在屏幕上打印这些单词,大约每秒可以生成超过 50,000 个组合...
如需更多信息,请发邮件至 "ubaidazad@gmail.com"
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
#include <iostream.h>
#include <conio.h>
#include <fstream.h>
#include <math.h>
int index_z=0,min,max;
char alpha[10],temp;
inline void intialize_values(int m) {
for (int j=0;j<m;j++)
{ alpha[j]='a'; }
}
inline int increament(int l) {
for (int a=l-1;a>=0;a--)
{
if (alpha[a]=='z' && min<=max) {
alpha[a]='a';
index_z++; }
else {
temp=alpha[a];
temp++;
alpha[a]=temp;
index_z=0;
break; }
}
if (index_z==l) {
l++; }
return l;
}
int main () {
int len,val,last,check;
double total=0E+0;
ofstream outfile("random.txt");
do {
system("cls");
cout << "min = ";
cin >> min;
cout << "max = ";
cin >> max; } while(min>max || max==0);
len=min;
last=min;
val=min;
for (int i=min;i<=max;i++)
{
intialize_values(val);
check=1;
while (check==1) {
for (int k=0;k<len;k++) {
cout << alpha[k]; }
cout << "\n";
total++;
len=increament(last);
if (len>last) {
last++;
check=0;
val++; }
}
}
cout << "\n\n\n";
cout << "Total Generated = " << total << endl;
double ch=0E+0;
for (int i=min;i<=max;i++) {
ch+=pow(26,i); }
if (total==ch)
cout << "\n\n" << "Task Completed Successfully.";
cout << "\n\n\n\t\t\tpress any key to exit...";
getch();
return 0;
}
|