refactored passphrase to use a simpler goodie.txt
Instead of building a hash from a source file containing index and word separated by spaces this new version builds an array of words and randomly selects elements from it. This will make it easier to modify the list of words since indexes don't need to be maintained by hand. This has the added bonus of being able to splice from the array, thus guaranteeing that we don't pick the same word more than once in a single passphrase.master
parent
02d847d65e
commit
f3fcbbe34e
|
@ -1,23 +1,17 @@
|
|||
my %passphrase = ();
|
||||
my @words = [];
|
||||
open(IN, '<passphrase/goodie.txt');
|
||||
while (my $line = <IN>) {
|
||||
chomp($line);
|
||||
my @res = split(/ /, $line);
|
||||
$passphrase{$res[0]} = $res[1];
|
||||
push(@words, $line);
|
||||
}
|
||||
close(IN);
|
||||
|
||||
if ($type ne 'E' && $q_check_lc =~ m/^passphrase ([1-9]+)(?: word| words|)$/i) {
|
||||
for (my $count = 0; $count < int($1); $count++) {
|
||||
my $ref_num = '';
|
||||
for (my $num = 0; $num < 5; $num++) {
|
||||
# alea iacta est!!!
|
||||
$ref_num .= int(rand(6)) + 1;
|
||||
}
|
||||
$answer_results .= "$passphrase{$ref_num} ";
|
||||
my $word_count = int($1);
|
||||
for (my $count = 0; $count < $word_count; $count++) {
|
||||
my $word = splice @words, (int(rand @words)), 1;
|
||||
$answer_results .= "$word ";
|
||||
}
|
||||
# Remove the trailing space
|
||||
chop $answer_results;
|
||||
$answer_results = qq(random passphrase: $answer_results);
|
||||
$answer_type = 'passphrase';
|
||||
$is_memcached = 0;
|
||||
|
|
15552
passphrase/goodie.txt
15552
passphrase/goodie.txt
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue