public static void fill(GpwData xx) { int c1, c2, c3; for (c1 = 0; c1 < 13; c1++) { for (c2 = 0; c2 < 26; c2++) { for (c3 = 0; c3 < 26; c3++) { xx.set_Renamed(c1, c2, c3, tris1[c1][c2][c3]); } // for c3 } // for c2 } // for c1 }
/// <summary> /// Generates a set of pronounceable passwords. /// </summary> /// <param name="PasswordCount">The number of passwords to generate.</param> /// <param name="PasswordLength">The character length of the passwords.</param> /// <returns>An ArrayList of passwords as strings.</returns> public ArrayList Generate(int PasswordCount,int PasswordLength) { if (data == null) { data = new GpwData(); } ArrayList result = new ArrayList(); int c1, c2, c3; long sum = 0; int nchar = 0; long ranno = 0; int pwnum = 0; double pik = 0; StringBuilder password = new StringBuilder(); System.Random ran = new System.Random(); // new random source seeded by clock // Pick a random starting point. for (pwnum = 0; pwnum < PasswordCount; pwnum++) { password = new System.Text.StringBuilder(PasswordLength); pik = ran.NextDouble(); // random number [0,1] ranno = (long) (pik * data.Sigma); // 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_Renamed(c1, c2, c3); if (sum > ranno) { password.Append(alphabet[c1]); password.Append(alphabet[c2]); password.Append(alphabet[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 < PasswordLength) { c1 = alphabet.IndexOf((System.Char) password[nchar - 2]); c2 = alphabet.IndexOf((System.Char) password[nchar - 1]); sum = 0; for (c3 = 0; c3 < 26; c3++) sum += data.get_Renamed(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_Renamed(c1, c2, c3); if (sum > ranno) { password.Append(alphabet[c3]); c3 = 26; // break for loop } // if sum } // for c3 nchar++; } // while nchar result.Add(password.ToString()); } // for pwnum return result; }