The so-called "full password" refers to all the possible passwords in the specified string. In the case of the string "0123456789", there are 100 possible 2-bit ciphers, that is, l^n. (L represents the length of the string, and N represents the number of bits to generate the password).
The first method: recursion. This is easier to understand, each break out a character, set to a new string, and then on the previous string. The code is as follows:
voidCpasswordcreatedlg::createpass1 (CString inStr,intm,cstring outstr) { if(m==0) {FP. Seektoend (); CString Tstr=outstr+l"\ n"; Fp. WriteString (TSTR);//fp is a cstdiofile, global variable Passflag++;//How many passwords are generated for the progress bar, for the Ulonglong typeintPersent=int((float) passflag/passscore* -);//passscore The total number of passwords to generateif(persent%5==0{m_progressctrl.setpos (persent);//m_progressctrl is Progress bar}}Else { for(intI=0; I<instr.getlength (); i++) {CreatePass1 (instr,m-1, Outstr+instr.mid (i,1)); } }}
The second approach: looping in a way that does not use recursion. The code is as follows, now if let me explain the meaning of the code, I really can't think of why the design at that time, unexpectedly can't understand why I was so cow B, can come up with the following code.
voidCpasswordcreatedlg::createpass2 (CString inStr,intm) {FP. Seektoend (); int*flag=New int[m];//to remove a character from a position in a string with a shaping pointer for(intI=0; i<m;i++) {Flag[i]=0; } intinstrlen=instr.getlength (); ULONGLONG Passcount= (ulonglong) Pow ((Double) instrlen,m); for(Ulonglong i=0; i<passcount;i++) { for(intt=1; t<m;t++) { if(flag[m-t]>0&&flag[m-t]%instrlen==0//This place is more awkward, I also forget how it came out of this idea. {Flag[m-t-1]++; Flag[m-t]=0; }} CString str=l""; for(intj=0; j<m;j++) {str+=Instr.getat (Flag[j]); } flag[m-1]++; STR+=l"\ n"; Fp. WriteString (str); Passflag++; intPersent=int((float) passflag/passscore* -); if(persent%5==0) {m_progressctrl.setpos (persent); } } Delete[] flag;}
The speed of generation is not very fast, about 20,000 or more in a second, it is basically useless. For example: At this speed to generate 5-bit full password, the number of passwords is 916132832, about 12 hours, if 6 bit, 7 bit, so it is basically useless, efficiency is too low. Hopefully the next step will be implemented with multiple threads, faster.
C + + implements full password generation