📄 passwordgenerator.java
字号:
package com.sslexplorer.core;
/* GPW - Generate pronounceable passwords
This program uses statistics on the frequency of three-letter sequences
in English to generate passwords. The statistics are
generated from your dictionary by the program loadtris.
See www.multicians.org/thvv/gpw.html for history and info.
Tom Van Vleck
THVV 06/01/94 Coded
THVV 04/14/96 converted to Java
THVV 07/30/97 fixed for Netscape 4.0
You are welcome to the source, if you
* Share your source with others freely
* Let me know you're using it
* Give me credit, and all the other pioneers, if you use the data or algorithms
*/
import java.util.Random;
public class PasswordGenerator {
int npw = 10;
int pwl = 8;
static GpwData data = null;
final static String alphabet = "abcdefghijklmnopqrstuvwxyz";
public String generate (int npw, int pwl) {
int c1, c2, c3;
long sum = 0;
int nchar;
long ranno;
int pwnum;
double pik;
StringBuffer password;
Random ran = new Random(); // new random source seeded by clock
if (data == null) {
data = new GpwData();
}
// Pick a random starting point.
for (pwnum=0; pwnum < npw; pwnum++) {
password = new StringBuffer(pwl);
pik = ran.nextDouble(); // random number [0,1]
ranno = (long)(pik * data.getSigma()); // weight by sum of frequencies
sum = 0;
for (c1=0; c1 < 26; c1++) {
for (c2=0; c2 < 26; c2++) {
for (c3=0; c3 < 26; c3++) {
sum += data.get(c1, c2, c3);
if (sum > ranno) {
password.append(alphabet.charAt(c1));
password.append(alphabet.charAt(c2));
password.append(alphabet.charAt(c3));
c1 = 26; // Found start. Break all 3 loops.
c2 = 26;
c3 = 26;
} // if sum
} // for c3
} // for c2
} // for c1
// Now do a random walk.
nchar = 3;
while (nchar < pwl) {
c1 = alphabet.indexOf(password.charAt(nchar-2));
c2 = alphabet.indexOf(password.charAt(nchar-1));
sum = 0;
for (c3=0; c3 < 26; c3++)
sum += data.get(c1, c2, c3);
if (sum == 0) {
break; // exit while loop
}
pik = ran.nextDouble();
ranno = (long)(pik * sum);
sum = 0;
for (c3=0; c3 < 26; c3++) {
sum += data.get(c1, c2, c3);
if (sum > ranno) {
password.append(alphabet.charAt(c3));
c3 = 26; // break for loop
} // if sum
} // for c3
nchar ++;
} // while nchar
return password.toString(); // Password generated
} // for pwnum
return null;
} // generate()
} // GpwWindow
// ================================================================
class GpwData {
static short tris[][][] = null;
static long sigma[] = null; // 125729
GpwData () {
int c1, c2, c3;
tris = new short[26][26][26];
sigma = new long[1];
GpwDataInit1.fill(this); // Break into two classes for NS 4.0
GpwDataInit2.fill(this); // .. its Java 1.1 barfs on methods > 65K
for (c1=0; c1 < 26; c1++) {
for (c2=0; c2 < 26; c2++) {
for (c3=0; c3 < 26; c3++) {
sigma[0] += (long) tris[c1][c2][c3];
} // for c3
} // for c2
} // for c1
} // constructor
void set(int x1, int x2, int x3, short v) {
tris[x1][x2][x3] = v;
} // set()
long get(int x1, int x2, int x3) {
return (long) tris[x1][x2][x3];
} // get()
long getSigma() {
return sigma[0];
} // get()
} // GpwData
// ================================================================
class GpwDataInit1 {
final static short tris1[][][] = {{ /* [13][26][26] */
/* A A */ {2,0,3,0,0,0,1,0,0,0,0,1,1,1,0,0,0,3,2,0,0,0,0,0,0,0},
/* A B */ {37,25,2,5,38,0,0,2,46,1,0,304,0,2,49,0,0,24,24,0,19,0,0,0,14,0},
/* A C */ {26,1,64,2,107,0,1,94,67,0,173,13,5,1,35,1,13,32,3,114,23,0,0,0,45,0},
/* A D */ {35,7,3,43,116,6,3,8,75,14,1,16,25,3,44,3,1,35,20,1,10,25,9,0,18,0},
/* A E */ {2,0,2,1,0,1,3,0,0,0,0,10,0,2,3,0,0,12,6,0,2,0,0,0,0,0},
/* A F */ {5,0,0,0,14,50,2,0,3,0,2,5,0,2,7,0,0,5,1,39,1,0,0,0,1,0},
/* A G */ {30,1,0,1,182,0,42,5,30,0,0,7,9,42,51,3,0,24,3,0,21,0,3,0,3,0},
/* A H */ {12,0,0,0,20,0,0,0,3,0,0,5,4,2,13,0,0,2,0,0,1,0,0,0,0,0},
/* A I */ {2,0,10,26,2,1,10,0,2,1,2,87,13,144,0,2,0,93,30,23,0,3,1,0,0,0},
/* A J */ {4,0,0,0,3,0,0,0,0,0,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0},
/* A K */ {11,0,1,1,98,1,0,1,15,0,0,3,0,0,5,1,0,3,0,1,2,0,3,0,8,0},
/* A L */ {78,20,34,45,124,21,24,5,109,0,28,237,31,3,53,23,0,7,16,69,29,26,5,0,26,2},
/* A M */ {70,57,1,1,98,3,0,1,68,0,0,3,38,2,43,69,0,3,14,3,12,0,2,0,14,0},
/* A N */ {114,6,156,359,103,8,146,12,141,2,57,4,0,89,61,1,4,1,124,443,29,6,1,3,28,9},
/* A O */ {0,0,1,0,0,0,0,0,0,0,0,3,1,0,0,0,0,3,2,2,2,0,0,0,0,0},
/* A P */ {29,3,0,1,59,1,0,86,25,0,1,14,1,1,37,94,0,9,22,30,8,0,0,0,9,0},
/* A Q */ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,14,0,0,0,0,0},
/* A R */ {124,64,101,233,115,12,47,5,188,3,61,55,68,34,46,25,6,94,48,189,5,22,5,1,172,2},
/* A S */ {19,3,32,0,71,0,1,81,49,0,22,3,19,2,19,34,4,0,152,211,12,0,1,0,17,1},
/* A T */ {50,3,41,2,863,4,0,144,352,0,5,14,6,3,144,0,0,60,13,106,57,1,5,0,8,5},
/* A U */ {0,5,23,35,5,5,38,1,0,1,3,33,4,23,0,4,1,35,52,56,0,1,0,7,0,1},
/* A V */ {35,0,0,1,108,0,0,0,49,0,0,1,0,0,19,0,0,0,0,0,3,1,0,0,6,0},
/* A W */ {30,10,0,4,3,6,2,2,2,0,10,13,4,15,3,0,0,6,3,5,0,0,0,0,2,0},
/* A X */ {3,0,0,0,4,0,0,0,22,0,0,1,0,0,7,2,0,0,1,1,0,0,3,0,3,0},
/* A Y */ {11,8,1,5,16,5,1,2,2,0,0,10,7,4,13,1,0,3,5,7,3,0,5,0,0,0},
/* A Z */ {10,0,0,1,22,0,0,0,10,0,0,0,0,0,7,0,0,0,0,2,2,0,0,0,4,11}},
/* B A */ {{0,17,74,11,1,2,19,4,8,0,10,68,7,73,1,7,0,110,54,55,9,1,3,1,12,1},
/* B B */ {7,0,0,0,16,0,0,0,10,0,0,24,0,0,9,0,0,2,3,0,2,0,0,0,14,0},
/* B C */ {2,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0},
/* B D */ {2,0,0,0,2,0,0,0,2,0,0,0,0,0,3,0,0,1,0,0,3,0,0,0,0,0},
/* B E */ {51,1,14,34,18,11,16,7,9,0,1,85,5,48,2,2,2,199,36,41,0,4,5,1,6,2},
/* B F */ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0},
/* B G */ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
/* B H */ {0,0,0,0,1,0,0,0,0,0,0,0,0,0,5,0,0,0,0,0,1,0,0,0,0,0},
/* B I */ {34,8,22,21,8,3,9,1,0,3,1,50,7,45,16,4,2,29,22,59,4,4,0,0,0,3},
/* B J */ {0,0,0,0,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0},
/* B K */ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
/* B L */ {57,0,0,0,519,0,0,0,35,0,0,0,0,0,47,0,0,0,0,0,32,1,0,0,3,0},
/* B M */ {0,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0},
/* B N */ {1,0,0,0,2,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0},
/* B O */ {62,7,4,21,3,2,9,3,8,1,1,46,8,63,58,2,0,55,15,20,46,6,17,10,19,0},
/* B P */ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0},
/* B Q */ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
/* B R */ {110,0,0,0,77,0,0,0,100,0,0,0,0,0,78,0,0,0,0,0,28,0,0,0,10,0},
/* B S */ {0,0,6,0,16,0,0,0,7,0,0,0,0,0,12,0,0,0,0,27,2,0,0,0,0,0},
/* B T */ {1,0,0,0,3,1,0,0,0,0,0,4,0,0,1,0,0,3,0,0,0,0,0,0,0,0},
/* B U */ {0,3,21,16,3,5,14,0,12,1,2,52,7,20,2,0,1,104,44,54,0,0,0,3,1,5},
/* B V */ {0,0,0,0,3,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
/* B W */ {0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
/* B X */ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
/* B Y */ {1,0,0,0,3,0,1,2,0,0,0,4,0,0,0,3,0,6,8,3,0,0,2,0,0,2},
/* B Z */ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}},
/* C A */ {{1,47,17,33,1,3,4,5,7,1,3,120,40,120,1,59,1,171,60,150,19,20,1,0,5,0},
/* C B */ {0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0},
/* C C */ {23,0,0,0,22,0,0,5,13,0,0,13,0,0,26,0,0,7,0,0,27,0,0,0,0,0},
/* C D */ {1,0,1,0,1,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0},
/* C E */ {23,6,4,17,6,6,1,2,13,0,0,50,12,109,7,43,0,76,63,22,1,0,4,0,2,1},
/* C F */ {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
/* C G */ {0,0,0,0,1,0,0,0,2,0,0,0,0,0,2,0,0,4,1,0,1,0,0,0,0,0},
/* C H */ {165,10,2,3,176,4,3,1,141,0,0,26,20,16,102,1,0,63,8,10,44,0,13,0,20,0},
/* C I */ {76,15,8,33,24,16,3,0,0,0,0,38,5,45,50,28,0,29,38,71,6,8,0,0,0,0},
/* C J */ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
/* C K */ {17,16,2,3,90,4,1,7,20,1,1,45,8,8,12,9,0,3,32,6,6,0,13,0,22,0},
/* C L */ {95,0,0,0,84,0,0,0,50,0,0,0,0,0,54,0,0,0,0,0,34,0,0,0,3,0},
/* C M */ {1,0,0,0,2,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0},
/* C N */ {2,0,0,0,1,0,0,0,4,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0},
/* C O */ {33,16,40,22,14,10,11,12,9,1,1,101,218,421,24,56,2,129,37,40,86,22,25,4,4,2},
/* C P */ {1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0},
/* C Q */ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,13,0,0,0,0,0},
/* C R */ {101,0,0,0,112,0,0,0,75,0,0,0,0,0,88,0,0,0,0,1,41,0,0,0,25,0},
/* C S */ {0,0,0,0,0,0,0,0,3,0,0,0,0,1,2,0,0,0,1,2,0,0,0,0,0,0},
/* C T */ {44,0,0,0,12,2,0,0,113,0,0,0,2,0,94,0,0,46,0,0,42,0,1,0,3,0},
/* C U */ {3,12,2,6,6,6,0,0,8,0,0,102,42,10,9,15,0,72,51,41,1,0,0,0,0,0},
/* C V */ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
/* C W */ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
/* C X */ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -