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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
| import java.io.*; import java.util.HashSet;
public class PasswordDict {
final public static String [] baseStr = { "0","1","2","3","4","5","6","7","8","9", "a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r", "s","t","u","v","w","x","y","z", "A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R", "S","T","U","V","W","X","Y","Z", "!","@","#","$","%","^","&","*","(",")","-","+","_","=","\\","|",":","'", ";","\"","<",">","?",",","."," ","~","`" };
public HashSet<String> resultSet= new HashSet<>();
public int passLength = 1;
public void FourOrSixNumberDict(String fileName,int status){ try{ File fileObj = new File(fileName); if(fileObj.exists()){ fileObj.delete(); fileObj.createNewFile(); System.out.println("system info: 文件已重新创建"); } FileOutputStream fos = new FileOutputStream(fileName,true); OutputStreamWriter osw = new OutputStreamWriter(fos, "utf-8"); BufferedWriter bw = new BufferedWriter(osw); for(int a = 0 ; a<10; a++){ for(int b = 0; b<10;b++){ for(int c = 0;c<10;c++){ for(int d=0;d<10;d++) { if (status == 0 || status == 1) { bw.write(baseStr[a] + baseStr[b] + baseStr[c] + baseStr[d] + "\n"); } if (status == 0 || status == 2) { for (int e = 0; e < 10; e++) { for (int f = 0; f < 10; f++) { bw.write(baseStr[a] + baseStr[b] + baseStr[c] + baseStr[d] + baseStr[e] + baseStr[f] + "\n"); } } } } } } } bw.flush(); osw.flush(); fos.flush(); if (status == 0) { System.out.println("system info: 4 位、6位密码字典生成 Success"); } else if (status == 1) { System.out.println("system info: 4 位密码字典生成 Success"); } else if (status == 2) { System.out.println("system info: 6 位密码字典生成 Success"); } }catch (FileNotFoundException e){ System.out.println("system info: 打开文件出错"); }catch (IOException e){ System.out.println("system info: 文件读写出错");
} }
public void recursionDict(HashSet<String> tempHashSet_1 ,int maxLength){ if(passLength <= maxLength){ if (tempHashSet_1 == null) { tempHashSet_1 = new HashSet<>(); for (int i = 0; i < baseStr.length; i++) { tempHashSet_1.add(baseStr[i]); } resultSet.addAll(tempHashSet_1); passLength ++; recursionDict(tempHashSet_1, maxLength); }else { HashSet<String> tempHashSet_2 = new HashSet<>(); for (String tempHashSet : tempHashSet_1){ for (int i = 0; i<baseStr.length;i++){ tempHashSet_2.add(tempHashSet + baseStr[i]); } } resultSet.addAll(tempHashSet_2); passLength ++; recursionDict(tempHashSet_2, maxLength); } } else { System.out.println("system info: 数据生成完成"); } }
public void outFile(String fileName){ try { File fileObj = new File(fileName); if (fileObj.exists()) { fileObj.delete(); fileObj.createNewFile(); System.out.println("system info: 文件已重新创建"); } FileOutputStream fos = new FileOutputStream(fileName, true); OutputStreamWriter osw = new OutputStreamWriter(fos, "utf-8"); BufferedWriter bw = new BufferedWriter(osw); for (String i : resultSet) { bw.write(i + "\n"); } bw.flush(); osw.flush(); fos.flush(); System.out.println("system info: 穷举法密码字典生成 Success"); }catch (FileNotFoundException e){ System.out.println("system info: 打开文件出错"); }catch (IOException e){ System.out.println("system info: 文件读写出错"); } }
public static void main(String[] args) { PasswordDict pd = new PasswordDict(); pd.FourOrSixNumberDict("D:\\FourNumberDict.txt",1);
pd.passLength = 1; pd.recursionDict(null,6); pd.outFile("D:\\MorePassWord.txt");
}
}
|