void createpassword()
{
#define passwordmax 8 //将生成密码的最大长度
char a[]="0123456789abcdefghijklmnopqrstuvwxyz"; //可能的字符
long ndictcount=sizeof(a); //获得密码词典长度
char cpass[passwordmax+2]; //将生成的密码
long nminl=1,nmaxl=3; //本例中密码长度从1-3
long array[passwordmax]; //密码词典下标
assert(nminl<=nmaxl && nmaxl<=passwordmax);//容错保证
long nlength=nminl;
register long j,i=0;
bool bnext;
cstdiofile file;
file.open("c:\dict.txt",cfile::modecreate|cfile::modewrite);
while(nlength<=nmaxl)
{
for(i=0;i
bnext=true;
while(bnext)
{
for(i=0;i
cpass[i]='';
file.writestring(cpass);
file.writestring("
");
for(j=nlength-1;j>=0;j--) //密码指针进位
{
array[j]++;
if(array[j]!=ndictcount-1)break;
else
{
array[j]=0;
if(j==0)bnext=false;
}
}
}
nlength++;
}
file.close();
}
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/10797429/viewspace-101631/ ,如需转载,请注明出处,否则将追究法律责任。