-
Notifications
You must be signed in to change notification settings - Fork 23
/
eff.js
46 lines (40 loc) · 1.51 KB
/
eff.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"use strict"
const effProps = {
"passId": document.getElementById('eff-pass'),
"passLength": document.getElementById('eff-length'),
"passEntropy": document.getElementById('eff-entropy'),
"setSize": document.getElementById('eff-set-size'),
"entropyCheck": document.getElementById('eff-entropy-check'),
}
/**
* Generate an EFF passphrase based on the chosen word list.
* @param {string} selection - An EFF word list.
*/
function generateEff(selection) {
let pass = ''
let wordList = ''
if (selection === 'Distant Words') {
wordList = effDistant
} else if (selection === 'Short Words') {
wordList = effShort
} else if (selection === 'Long Words') {
wordList = effLong
} else if (selection === 'Game of Thrones') {
wordList = effGameOfThrones
} else if (selection === 'Harry Potter') {
wordList = effHarryPotter
} else if (selection === 'Star Trek') {
wordList = effStarTrek
} else if (selection === 'Star Wars') {
wordList = effStarWars
}
wordList = uniquesOnly(wordList) // Force unique elements in array.
const entropy = getEntropy()
const len = Math.ceil(entropy / Math.log2(wordList.length))
pass = generatePass(len, wordList, true, effProps.entropyCheck.checked).trim()
pass = pass.replace(/ /g, '-')
effProps.passId.innerText = pass
effProps.passLength.innerText = pass.length + ' characters'
effProps.setSize.innerText = wordList.length.toLocaleString() + ' words'
effProps.passEntropy.innerText = Math.floor(len * Math.log2(wordList.length)) + ' bits'
}