Explanation of Java Dictionary Generation Algorithm
- 2021-07-01 07:31:41
- OfStack
In practical applications, people can use a variety of passwords, but no matter how many, their composition is not far from being composed of printable characters, we can think that
class CreateDic{
private int BitNum;
private String Str;
public void SetBitNum(int num)
{
BitNum=num;
}
public void SetStr(String str)
{
Str=str;
}
public int GetBitNum(){
return BitNum;
}
public String GetStr(){
return Str;
}
public List<String> GetDic(){
int[] tmparray=new int[BitNum];
List<String> final_list=new ArrayList<String>();
String result="";
for(int i=0;i<BitNum;i++)
tmparray[i]=0;
int nCount=0;
while(true)
{
result="";
for(int i=0;i<BitNum;i++)
{
result+=Str.charAt(tmparray[i]);
}
nCount++;
System.out.println(result);
final_list.add(result+"\r\n");
// Begin to proceed 1 Wheel cycle
int length=Str.length();
int mark=0;
for(int j=BitNum-1;j>=0;j--)
{
if(tmparray[j]==length-1){
if(j!=0){
continue;
}
else{
mark=1;
break;
}
}
else{
tmparray[j]++;
for(int k=j+1;k<BitNum;k++)
{
tmparray[k]=0;
}
break;
}
}
if(mark==1){
break;
}
}
System.out.println("1 Total number of passwords output: "+nCount);
return final_list;
}
}
It can be said that if there are three characters 1 that make up the password, which are "abc", and the password length is 6, then BitNum can be set to 6 and the content of Str is "abc", so that all possible password strings can be obtained as return values
Summarize