From 6458d09cda6e5ab26333b2f255e7ad1cc0e2e2f0 Mon Sep 17 00:00:00 2001 From: TLINDEN Date: Mon, 3 Aug 2015 21:14:59 +0200 Subject: [PATCH] allow 0-9 in words as well --- README.md | 2 ++ dicepwgen.1 | 41 ++++++++++++++++++++++++++++++++++++++--- dicepwgen.c | 16 +++++++++++++--- dicepwgen.h | 1 + dicepwgen.pod | 39 ++++++++++++++++++++++++++++++++++++++- dictfile.c | 16 +++++++++------- dictfile.h | 1 + 7 files changed, 102 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 0c4f603..98c8d02 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,8 @@ modify `$PREFIX` during installation time like this: /usr/share/dict/american-english) -l --minlen Minimum word len (default: 5) -m --maxlen Maximum word len (default: 10) + -n --dontjump Use all words in the dict file, e.g. + if it is an original diceware list -d --debug Enable debug output -v --version Print program version -h -? --help Print this help screen diff --git a/dicepwgen.1 b/dicepwgen.1 index 7b3ee51..971dd40 100644 --- a/dicepwgen.1 +++ b/dicepwgen.1 @@ -133,7 +133,7 @@ .\" ======================================================================== .\" .IX Title "DICEPWGEN 1" -.TH DICEPWGEN 1 "2015-08-02" "perl v5.18.2" "User Contributed Perl Documentation" +.TH DICEPWGEN 1 "2015-08-03" "perl v5.18.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l @@ -142,7 +142,7 @@ dicepwgen \- A diceware password generator .SH "SYNOPSIS" .IX Header "SYNOPSIS" -.Vb 11 +.Vb 10 \& Usage: dice [\-tcfvhd] \& Options: \& \-t \-\-humantoss Asks interactively for rolled dices @@ -151,6 +151,8 @@ dicepwgen \- A diceware password generator \& /usr/share/dict/american\-english) \& \-l \-\-minlen Minimum word len (default: 5) \& \-m \-\-maxlen Maximum word len (default: 10) +\& \-n \-\-dontjump Use all words in the dict file, e.g. +\& if it is an original diceware list \& \-d \-\-debug Enable debug output \& \-v \-\-version Print program version \& \-h \-? \-\-help Print this help screen @@ -170,11 +172,35 @@ minimum and maximum word length. You can tell dicepwgen to use another dictionary file with the option \fB\-f\fR. .PP +If you're using a precomputed diceware list, use the parameter +\&\fB\-n\fR, in which case dicepwgen will use all entries in the file. +.PP The program only uses words which contain 7bit \s-1ASCII\s0 letters -(a\-zA-Z), which are easier for password usage anyway. +(a\-zA\-Z0\-9), which are easier for password usage anyway. .SH "FILES" .IX Header "FILES" \&\fB/usr/share/dict/american\-english\fR: default dictionary file. +.PP +You can use almost any dictionary file you want. Dicepwgen expects +the file to be in the following format: one word per line. +.PP +You can also use precomputed diceware word lists by adding the +option \fB\-n\fR to the commandline. If the file already contains +numbers, you have to remove them before using. Say, the file +looks like this: +.PP +.Vb 4 +\& 11126 abase +\& 11131 abash +\& 11132 abate +\& 11133 abbas +.Ve +.PP +Prepare the file with this shell oneliner: +.PP +.Vb 1 +\& grep "^[0\-9]" dicewarelist.txt | awk \*(Aq{print $2}\*(Aq >> newlist.txt +.Ve .SH "SEE ALSO" .IX Header "SEE ALSO" @@ -185,6 +211,15 @@ The program only uses words which contain 7bit \s-1ASCII\s0 letters In order to report a bug, unexpected behavior, feature requests or to submit a patch, please open an issue on github: . +.PP +Current known issues: +.IP "\(bu" 4 +The program does not count the lines in a dictionary file before +using it. If the file contains a low number of entries (e.g. because +it is a precomputed diceware word list and \fB\-n\fR has not been +specified), it seems to \*(L"hang\*(R". In fact it runs very long because it +jumps over a random number of entries and restarts from the beginning +again and again til the required number of words has been collected (7776). .SH "LICENSE" .IX Header "LICENSE" This software is licensed under the \s-1GNU GENERAL PUBLIC LICENSE\s0 version 3. diff --git a/dicepwgen.c b/dicepwgen.c index 0f47961..63e8c63 100644 --- a/dicepwgen.c +++ b/dicepwgen.c @@ -32,6 +32,8 @@ int usage() { " /usr/share/dict/american-english)\n" "-l --minlen Minimum word len (default: 5)\n" "-m --maxlen Maximum word len (default: 10)\n" + "-n --dontjump Use all words in the dict file, e.g.\n" + " if it is an original diceware list\n" "-d --debug Enable debug output\n" "-v --version Print program version\n" "-h -? --help Print this help screen\n" @@ -46,8 +48,7 @@ int main (int argc, char **argv) { WMIN = 6; WMAX = 10; - humantoss = 0; - verbose = 0; + humantoss = verbose = dontjump = 0; static struct option longopts[] = { { "wordcount", required_argument, NULL, 'c' }, @@ -55,12 +56,13 @@ int main (int argc, char **argv) { { "maxlen", required_argument, NULL, 'm' }, { "humantoss", required_argument, NULL, 't' }, { "dictfile", required_argument, NULL, 'f' }, + { "dontjump", no_argument, NULL, 'n' }, { "version", no_argument, NULL, 'v' }, { "help", no_argument, NULL, 'h' }, { "debug", no_argument, NULL, 'd' }, }; - while ((opt = getopt_long(argc, argv, "l:m:tf:c:vh?d", longopts, NULL)) != -1) { + while ((opt = getopt_long(argc, argv, "l:m:tf:c:vh?dn", longopts, NULL)) != -1) { switch (opt) { case 'v': fprintf(stderr, "This is %s version %s\n", argv[0], VERSION); @@ -85,6 +87,9 @@ int main (int argc, char **argv) { case 'd': verbose++; break; + case 'n': + dontjump = 1; + break; case 'f': dictfile = malloc(strlen(optarg)); strncpy(dictfile, optarg, strlen(optarg)); @@ -99,6 +104,11 @@ int main (int argc, char **argv) { dictfile = STRINGIZE_VALUE_OF(DICTFILE); } + if(dontjump) { + WMIN = 0; + WMAX = 128; + } + debug(" using dictfile: %s", dictfile); debug("minimum word length: %d", WMIN); debug("maximum word length: %d", WMAX); diff --git a/dicepwgen.h b/dicepwgen.h index 2114e8e..5911152 100644 --- a/dicepwgen.h +++ b/dicepwgen.h @@ -42,6 +42,7 @@ int humantoss; int verbose; +int dontjump; int WMIN; int WMAX; diff --git a/dicepwgen.pod b/dicepwgen.pod index 8c18089..2b0833f 100644 --- a/dicepwgen.pod +++ b/dicepwgen.pod @@ -12,6 +12,8 @@ dicepwgen - A diceware password generator /usr/share/dict/american-english) -l --minlen Minimum word len (default: 5) -m --maxlen Maximum word len (default: 10) + -n --dontjump Use all words in the dict file, e.g. + if it is an original diceware list -d --debug Enable debug output -v --version Print program version -h -? --help Print this help screen @@ -31,13 +33,33 @@ minimum and maximum word length. You can tell dicepwgen to use another dictionary file with the option B<-f>. +If you're using a precomputed diceware list, use the parameter +B<-n>, in which case dicepwgen will use all entries in the file. + The program only uses words which contain 7bit ASCII letters -(a-zA-Z), which are easier for password usage anyway. +(a-zA-Z0-9), which are easier for password usage anyway. =head1 FILES B: default dictionary file. +You can use almost any dictionary file you want. Dicepwgen expects +the file to be in the following format: one word per line. + +You can also use precomputed diceware word lists by adding the +option B<-n> to the commandline. If the file already contains +numbers, you have to remove them before using. Say, the file +looks like this: + + 11126 abase + 11131 abash + 11132 abate + 11133 abbas + +Prepare the file with this shell oneliner: + + grep "^[0-9]" dicewarelist.txt | awk '{print $2}' >> newlist.txt + =head1 SEE ALSO L @@ -50,6 +72,21 @@ In order to report a bug, unexpected behavior, feature requests or to submit a patch, please open an issue on github: L. +Current known issues: + +=over + +=item * + +The program does not count the lines in a dictionary file before +using it. If the file contains a low number of entries (e.g. because +it is a precomputed diceware word list and B<-n> has not been +specified), it seems to "hang". In fact it runs very long because it +jumps over a random number of entries and restarts from the beginning +again and again til the required number of words has been collected (7776). + +=back + =head1 LICENSE This software is licensed under the GNU GENERAL PUBLIC LICENSE version 3. diff --git a/dictfile.c b/dictfile.c index 7ef6fc7..559ae9f 100644 --- a/dictfile.c +++ b/dictfile.c @@ -106,18 +106,20 @@ char **fetch_dict(char *dictfile) { LOOP: while ((linelen = getline(&line, &len, DICT)) != -1) { - if(jump > 0) { - jump--; - continue; - } - else { - jump = rand_lim(32); + if(! dontjump) { + if(jump > 0) { + jump--; + continue; + } + else { + jump = rand_lim(32); + } } if(linelen >= WMIN+1 && linelen <= WMAX+1) { line[linelen-1] = '\0'; /* remove newline */ for(i=0; i