mirror of
https://github.com/dmuth/diceware.git
synced 2024-11-24 17:56:35 -05:00
Updated PHP and shell script to create wordlists for 6 and 7 dice rolls.
This commit is contained in:
parent
360086c676
commit
4cb0e0e1c7
5 changed files with 326711 additions and 23 deletions
|
@ -14,16 +14,73 @@ if (php_sapi_name() != "cli") {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Print out syntax and exit.
|
||||
*/
|
||||
function printSyntax($progname) {
|
||||
|
||||
print "Syntax: $progname [ --dice n ]\n\n"
|
||||
. "\t--dice Number of dice to generate a wordlist for. Must be between 5 and 7 inclusive. Defaults to 5.\n"
|
||||
. "\n"
|
||||
;
|
||||
|
||||
exit(1);
|
||||
|
||||
} // End of printSyntax()
|
||||
|
||||
|
||||
/**
|
||||
* Parse our arguments.
|
||||
*
|
||||
* @param array $argv Our command line arguments
|
||||
*
|
||||
* @return array An associative array of whatever we parsed out.
|
||||
*/
|
||||
function parseArgs($argv) {
|
||||
|
||||
$retval = array();
|
||||
|
||||
$progname = array_shift($argv);
|
||||
|
||||
while ($value = array_shift($argv)) {
|
||||
|
||||
$value_next = "";
|
||||
if (isset($argv[0])) {
|
||||
$value_next = $argv[0];
|
||||
}
|
||||
|
||||
if ($value == "-h" || $value == "--help") {
|
||||
printSyntax($progname);
|
||||
}
|
||||
|
||||
if ($value == "--dice") {
|
||||
$retval["dice"] = $value_next;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ($retval["dice"] < 5 || $retval["dice"] > 7) {
|
||||
printSyntax($progname);
|
||||
}
|
||||
|
||||
return($retval);
|
||||
|
||||
} // End of parseArgs()
|
||||
|
||||
|
||||
/**
|
||||
* Read in our wordlist from Google and return an array with all words that
|
||||
* passed validation.
|
||||
*
|
||||
* @param string $filename The filename
|
||||
*
|
||||
* @param integer $dice How many dice rolls to make? This number will
|
||||
* be between 5 and 8, inclusive.
|
||||
*
|
||||
* @return array An array of words
|
||||
*
|
||||
*/
|
||||
function readWordListPeterNorvig($filename) {
|
||||
function readWordListPeterNorvig($filename, $dice) {
|
||||
|
||||
$retval = array();
|
||||
|
||||
|
@ -33,16 +90,30 @@ function readWordListPeterNorvig($filename) {
|
|||
}
|
||||
|
||||
$count = 0;
|
||||
$max_count = array(
|
||||
5 => 7776,
|
||||
6 => 46656,
|
||||
7 => 279936,
|
||||
//8 => 1679616, // Can't do this with only 1/3rd million words ATM.
|
||||
);
|
||||
|
||||
//
|
||||
// We will tweak acceptable word length based on the number of
|
||||
// dice we are rolling so we get enough words.
|
||||
//
|
||||
$word_lengths = array(
|
||||
5 => array("min" => 4, "max" => 7),
|
||||
6 => array("min" => 5, "max" => 6),
|
||||
7 => array("min" => 4, "max" => 11),
|
||||
);
|
||||
|
||||
while ($line = fgets($fp)) {
|
||||
|
||||
$line = rtrim($line);
|
||||
list($word, $freq) = explode("\t", $line);
|
||||
$len = strlen($word);
|
||||
|
||||
//
|
||||
// Keep all words between 4 and 7 characters
|
||||
//
|
||||
if ($len < 4 || $len > 7) {
|
||||
if ($len < $word_lengths[$dice]["min"] || $len > $word_lengths[$dice]["max"]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -50,7 +121,7 @@ function readWordListPeterNorvig($filename) {
|
|||
|
||||
$count++;
|
||||
|
||||
if ($count > 7776) {
|
||||
if ($count > $max_count[$dice]) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -112,20 +183,17 @@ function getJsArray($words) {
|
|||
/**
|
||||
* Our main entry point.
|
||||
*/
|
||||
function main() {
|
||||
function main($argv) {
|
||||
|
||||
$params = parseArgs($argv);
|
||||
|
||||
//
|
||||
// Read our file
|
||||
//
|
||||
$filename = "count_1w.txt";
|
||||
$words = readWordListPeterNorvig($filename);
|
||||
$words = readWordListPeterNorvig($filename, $params["dice"]);
|
||||
//print_r($words); // Debugging
|
||||
|
||||
//
|
||||
// Match words to dicerolls
|
||||
//
|
||||
//$rolls = getDiceRolls($words);
|
||||
|
||||
//
|
||||
// Get our Javascript
|
||||
//
|
||||
|
@ -136,6 +204,6 @@ function main() {
|
|||
} // End of main()
|
||||
|
||||
|
||||
main();
|
||||
main($argv);
|
||||
|
||||
|
||||
|
|
|
@ -8,17 +8,27 @@ set -e
|
|||
|
||||
pushd $(dirname $0) > /dev/null
|
||||
|
||||
JS="wordlist.js"
|
||||
|
||||
JS="wordlist-5-dice.js"
|
||||
echo "# "
|
||||
echo "# Creating wordlist '$JS'..."
|
||||
echo "# "
|
||||
./create-wordlist.php --dice 5 > ${JS}
|
||||
|
||||
JS="wordlist-6-dice.js"
|
||||
echo "# "
|
||||
echo "# Creating wordlist '$JS'..."
|
||||
echo "# "
|
||||
./create-wordlist.php --dice 6 > ${JS}
|
||||
|
||||
JS="wordlist-7-dice.js"
|
||||
echo "# "
|
||||
echo "# Creating wordlist '$JS'..."
|
||||
echo "# "
|
||||
./create-wordlist.php --dice 7 > ${JS}
|
||||
|
||||
echo "# "
|
||||
echo "# Creating wordlist Javascript..."
|
||||
echo "# "
|
||||
|
||||
#./create-wordlist.php # Debugging
|
||||
./create-wordlist.php > ${JS}
|
||||
|
||||
echo "# "
|
||||
echo "# Done! List created at ${JS}"
|
||||
echo "# Done!"
|
||||
echo "# "
|
||||
|
||||
|
||||
|
|
46665
wordlist/wordlist-6-dice.js
Normal file
46665
wordlist/wordlist-6-dice.js
Normal file
File diff suppressed because it is too large
Load diff
279945
wordlist/wordlist-7-dice.js
Normal file
279945
wordlist/wordlist-7-dice.js
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue