Skip to content

Commit

Permalink
fix regression where entropy was not getting set correctly per generator
Browse files Browse the repository at this point in the history
  • Loading branch information
atoponce committed Sep 11, 2017
1 parent 52d86b4 commit fa46ebf
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 51 deletions.
130 changes: 80 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,56 +8,86 @@ be needed to view the emoji characters correctly.

Options are:

--help
Print this help and exit.

--diceware <language>
Choose a Diceware language. Default is English.
<language> must be one of:
Basque, Beale, Bulgarian, Catalan, Chinese, Czech,
Danish, Dutch, English, Esperanto, Finnish, French,
German, Italian, Japanese, Maori, Norwegian, Polish,
Portuguese, Russian, Slovenian, Spanish, Swedish, Turkish.

--eff <wordlist>
Choose an EFF wordlist. Default is Short.
<wordlist> must be one of:
Distant, Long, Short.

--alternate <wordlist>
Choose an alternate wordlist. Default is PGP.
<wordlist> must be one of:
Bitcoin, Elvish, Klingon, PGP
RockYou, Simpsons, Trump

--ninja
Choose Secret Ninja encoding.

--cosby
Choose Bill Cosby Bebob.

--kpop
Choose Korean K-pop words.

--random <base>
Choose a number base to generated. Default is Base94
<base> must be one of:
Base94, Base64, Base32, Base16, Base10.

--only <generator>
Choose a generator instead of printing all six (default).
NOTE: A font supporting emoji may be needed for the Emoji generator.
<generator> must be one of:
Diceware, EFF, Alternate, Pseudowords, Random, Emoji

--min-entropy <number>
Set a minimum entropy requirement in bits. Default is 70.

--json
Output the passwords and meta in JSON format.

--hyphenate
Add hyphens to the Diceware, EFF, and Alternate passphrases.
-h
--help
Print this help and exit.

-d <language>
--diceware <language>
Choose a Diceware language. Default is English.
<language> must be one of:
Basque, Beale, Bulgarian, Catalan, Chinese, Czech,
Danish, Dutch, English, Esperanto, Finnish, French,
German, Italian, Japanese, Maori, Norwegian, Polish,
Portuguese, Russian, Slovenian, Spanish, Swedish, Turkish.

-e <wordlist>
--eff <wordlist>
Choose an EFF wordlist. Default is Short.
<wordlist> must be one of:
Distant, Long, Short.

-a <wordlist>
--alternate <wordlist>
Choose an alternate wordlist. Default is Trump.
<wordlist> must be one of:
Elvish, Klingon, PGP, Rockyou, Simposons, Trump

-b <language>
--bitcoin <language>
Choose a Bitcoin language. Default is English.
<language> must be one of:
Chinese, English, French, Italian, Japanese, Korean
NOTE:
Simplified Chinese is the default Chinese character set.
If you want to use Traditional Chinese, use --traditional.

-t
--traditional
Use the Traditional Chinese character set with Bitcoin.

-s
--system
Use /usr/share/dict/words for building your passphrase.
Obviously, the more words in that file, the more entropy per word.
Also, larger system word lists will contain more obscure words.

-n
--ninja
Choose Secret Ninja encoding.

-c
--cosby
Choose Bill Cosby Bebob.

-k
--kpop
Choose Korean K-pop words.

-e <base>
--random <base>
Choose a number base to generated. Default is Base94
<base> must be one of:
Base94, Base64, Base32, Base16, Base10.

-o <generator>
--only <generator>
Choose a generator instead of printing all six (default).
<generator> must be one of:
Alternate, Bitcoin, Diceware, EFF System,
Pseudowords, Random, or Emoji

-m <number>
--min-entropy <number>
Set a minimum entropy requirement in bits. Default is 70.

-j
--json
Output the passwords and meta in JSON format.

-H
--hyphenate
Add hyphens to the Diceware, EFF, and Alternate passphrases.

Output can be valid JSON, meant to be both human and machine parseable. Default
is unformatted plaintext:
Expand Down
16 changes: 15 additions & 1 deletion nodepassgen
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const crypto = require('crypto');
var spaces=false;
var results = [];
var args = process.argv;
var entropy = get_entropy();

function print_usage() {
console.log("Usage: node main.js [OPTION [ARG]]...");
Expand Down Expand Up @@ -284,6 +283,7 @@ function generate_diceware() {
process.exit(1);
}
var assoc_arr = {};
var entropy = get_entropy();
var len = Math.ceil(entropy/Math.log2(wordlist.length));
var pass = generate_pass(len, wordlist, true);
if ((args.indexOf("--hyphenate") != -1) || (args.indexOf("-H")) != -1) {
Expand Down Expand Up @@ -329,6 +329,7 @@ function generate_eff() {
process.exit();
}
var assoc_arr = {};
var entropy = get_entropy();
var len = Math.ceil(entropy/Math.log2(wordlist.length));
var pass = generate_pass(len, wordlist, true);
if ((args.indexOf("--hyphenate") != -1) || (args.indexOf("-H")) != -1) {
Expand Down Expand Up @@ -391,6 +392,7 @@ function generate_alternate() {
process.exit(1);
}
var assoc_arr = {};
var entropy = get_entropy();
var len = Math.ceil(entropy/Math.log2(wordlist.length));
var pass = generate_pass(len, wordlist, true);
if ((args.indexOf("--hyphenate") != -1) || (args.indexOf("-H")) != -1) {
Expand Down Expand Up @@ -462,6 +464,7 @@ function generate_bitcoin() {
process.exit(1);
}
var assoc_arr = {};
var entropy = get_entropy();
var len = Math.ceil(entropy/Math.log2(wordlist.length));
var pass = generate_pass(len, wordlist, true);
if ((args.indexOf("--hyphenate") != -1) || (args.indexOf("-H")) != -1) {
Expand All @@ -479,6 +482,7 @@ function generate_sys_pass() {
var dict = fs.readFileSync("/usr/share/dict/words").toString();
var wordlist = dict.split('\n');
var assoc_arr = {};
var entropy = get_entropy();
var len = Math.ceil(entropy/Math.log2(wordlist.length));
var pass = generate_pass(len, wordlist, true);
if ((args.indexOf("--hyphenate") != -1) || (args.indexOf("-H")) != -1) {
Expand All @@ -494,6 +498,7 @@ function generate_sys_pass() {

function generate_ninja() {
var ninja = ['ka','zu','mi','te','ku','lu','ji','ri','ki','zu','me','ta','rin','to','mo','no','ke','shi','ari','chi','do','ru','mei','na','fu','zi'];
var entropy = get_entropy();
var len = Math.ceil(entropy/Math.log2(ninja.length));
var pass = "";

Expand All @@ -509,6 +514,7 @@ function generate_ninja() {
function generate_cosby() {
// 32 unique words = 5 bits of entropy per word
var cosby = ['Bada','Badum','Bee','Bloo','Bop','Caw','Derp','Dip','Doo','Dub','Hip','Ka','Loo','Meep','Mim','Moom','Na','Naw','Nerp','Nup','Pa','Papa','Spee','Squee','Squoo','Woobly','Wop','Yee','Zap','Zip','Zop','Zoop','Zow'];
var entropy = get_entropy();
var len = Math.ceil(entropy/Math.log2(cosby.length));
var pass = "";

Expand All @@ -524,6 +530,7 @@ function generate_cosby() {
function generate_kpop() {
// 64 unique words = 6 bits of entropy per word
var kpop = ['A','Ah','Bae','Bin','Bo','Choi','Chul','Da','Do','Dong','Eun','Gi','Gun','Ha','Hae','Hee','Ho','Hu','Hwa','Hwan','Hye','Hyo','Hyun','Il','In','Ja','Jae','Ji','Jin','Jong','Joo','Joon','Ju','Jun','Jung','Ki','Kun','Kyu','Lee','Mi','Min','Moon','Nam','Ok','Park','Rin','Seo','Seul','Shi','Sik','So','Song','Soo','Su','Sun','Sung','Won','Woo','Ye','Yeon','Yoo','Yu','Yul','Yun'];
var entropy = get_entropy();
var len = Math.ceil(entropy/Math.log2(kpop.length));
var pass = "";

Expand All @@ -544,6 +551,7 @@ function generate_babble() {
var c_ent = Math.log2(consonants.length);
var out_ent = (2*c_ent)+(2*v_ent);
var in_ent = (3*c_ent)+(2*v_ent);
var entropy = get_entropy();
entropy = entropy - (2*out_ent);
var len = Math.ceil(entropy/in_ent);
var tot_ent = out_ent + (len*in_ent) + out_ent;
Expand Down Expand Up @@ -609,6 +617,7 @@ function generate_base94() {
for (i=0; i<94; i++) {
s += String.fromCharCode(33+i);
}
var entropy = get_entropy();
var len = Math.ceil(entropy/Math.log2(s.length));
var pass = generate_pass(len, s);
assoc_arr["Generator"] = "Random";
Expand All @@ -622,6 +631,7 @@ function generate_base94() {
function generate_base64() {
var assoc_arr = {};
var s = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/";
console.log(entropy);
var len = Math.ceil(entropy/Math.log2(s.length));
var pass = generate_pass(len, s);
assoc_arr["Generator"] = "Random";
Expand All @@ -635,6 +645,7 @@ function generate_base64() {
function generate_base32() {
var assoc_arr = {};
var s = "0123456789abcdefghjkmnpqrstvwxyz";
console.log(entropy);
var len = Math.ceil(entropy/Math.log2(s.length));
var pass = generate_pass(len, s);
var result = "Base32: '" + pass + "', ";
Expand All @@ -649,6 +660,7 @@ function generate_base32() {
function generate_base16() {
var assoc_arr = {};
var s = "0123456789abcdef"
console.log(entropy);
var len = Math.ceil(entropy/Math.log2(s.length));
var pass = generate_pass(len, s);
var result = "Base16: '" + pass + "', ";
Expand All @@ -663,6 +675,7 @@ function generate_base16() {
function generate_base10() {
var assoc_arr = {};
var s = "0123456789"
console.log(entropy);
var len = Math.ceil(entropy/Math.log2(s.length));
var pass = generate_pass(len, s);
var result = "Base10: '" + pass + "', ";
Expand Down Expand Up @@ -741,6 +754,7 @@ function generate_emoji() {
const emoji_wordlist = require('./lists/random_emoji');
var wordlist = emoji_wordlist.wordlist;
var assoc_arr = {};
console.log(entropy);
var len = Math.ceil(entropy/Math.log2(wordlist.length));
var pass = generate_pass(len, wordlist, true);
pass = pass.replace(/ /g,"");
Expand Down

0 comments on commit fa46ebf

Please sign in to comment.