Skip to content

Instantly share code, notes, and snippets.

@branneman
Last active January 2, 2018 02:23

Revisions

  1. branneman renamed this gist Mar 16, 2017. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. branneman revised this gist Mar 16, 2017. No changes.
  3. branneman created this gist Mar 16, 2017.
    34 changes: 34 additions & 0 deletions app.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    const map = fn => list => list.map(fn);
    const filter = fn => list => list.filter(fn);
    const compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args)));
    const tail = list => list.slice(1);
    const fill = val => num => new Array(num).fill(val);

    const getFileContents = file => require('fs').readFileSync(file, { encoding: 'utf8' });

    const split = char => str => str.split(char);
    const join = char => list => list.join(char);

    const isWordLine = str => /[1-6]{5}\t.+/.test(str);

    const getWordList = compose(map(split('\t')), filter(isWordLine), split('\n'), getFileContents);

    const wordList = getWordList('eff.wordlist.txt');

    const roll1D6 = () => Math.round((Math.random() * 5) + 1);
    const roll5D6 = () => map(roll1D6)(fill(0)(5));

    const getWord = n => wordList.find(i => i[0] === n);
    const getRandomWord = compose(join(' '), tail, getWord, join(''), roll5D6);
    const getRandomWords = compose(join(' '), map(getRandomWord), fill(0));

    const app = len => compose(join('\n'), map(() => getRandomWords(len)), fill(0));

    //
    // App
    //
    const numberOfWordsInPassword = 8;
    const numberOfPasswords = 25;
    const out = app(numberOfWordsInPassword)(numberOfPasswords);

    console.log(out);
    17 changes: 17 additions & 0 deletions eff_large_wordlist.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    11111 abacus
    11112 abdomen
    11113 abdominal
    11114 abide
    11115 abiding
    11116 ability
    11121 ablaze
    11122 able
    11123 abnormal
    11124 abrasion
    11125 abrasive
    11126 abreast
    11131 abridge
    11132 abroad
    ...

    See: https://www.eff.org/files/2016/07/18/eff_large_wordlist.txt