-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
156 lines (155 loc) · 3.4 KB
/
app.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
if ('serviceWorker' in navigator) {
window.addEventListener('load', function() {
navigator.serviceWorker.register('/diceware/service-worker.js')
.then(function (reg){
console.log('sw registered:', reg);
}, /*catch*/ function(error) {
console.log('Service worker registration failed:', error);
});
});
}
var app = new Vue({
el: '#app',
data: {
dicewarelist: {
starwars: {
minmax: [1,20],
number: 3,
list: window.starwars,
join: '-'
},
largewordlist: {
minmax: [1,6],
number: 5,
list: window.eff_large_wordlist,
join: ''
},
shortwordlist1: {
minmax: [1,6],
number: 4,
list: window.eff_short_wordlist_1,
join: ''
},
shortwordlist2: {
minmax: [1,6],
number: 4,
list: window.eff_short_wordlist_2,
join: ''
},
originaldiceware: {
minmax: [1,6],
number: 5,
list: window.diceware_wordlist,
join: ''
},
startrek: {
minmax: [1,20],
number: 3,
list: window.startrek,
join: '-'
},
gameofthrones: {
minmax: [1,20],
number: 3,
list: window.gameofthrones,
join: '-'
},
mnemonicencoding: {
minmax: [1,6],
number: 4,
list: window.mnemonicencoding,
join: ''
}
},
phraselength: 5,
selected: 'starwars',
options: {
1: {
name: 'Star Wars',
shortcode: 'starwars'
},
2: {
name: 'EFF Large Wordlist',
shortcode: 'largewordlist'
},
3: {
name: 'EFF Short Wordlist #1',
shortcode: 'shortwordlist1'
},
4: {
name: 'EFF Short Wordlist #2',
shortcode: 'shortwordlist2'
},
5: {
name: 'Original Diceware Wordlist',
shortcode: 'originaldiceware'
},
6: {
name: 'Star Trek',
shortcode: 'startrek'
},
7: {
name: 'Game Of Thrones',
shortcode: 'gameofthrones'
},
8: {
name: 'Mnemonic Encoding',
shortcode: 'mnemonicencoding'
}
},
curcode: [],
manual: ''
},
methods: {
cryptorandom: function(min, max) {
/* https://github.com/password-diet/password.diet/blob/master/app/scripts/components/home.js */
var byteArray = new Uint8Array(1);
window.crypto.getRandomValues(byteArray);
var range = max - min + 1;
var max_range = 256;
if (byteArray[0] >= Math.floor(max_range / range) * range) {
return this.cryptorandom(min, max);
}
return min + (byteArray[0] % range);
},
newrandom: function() {
this.curcode = [];
for (var j = 0; j<this.phraselength; j++) {
var dwlist = this.dicewarelist[this.selected];
var nums = dwlist.minmax;
var num = dwlist.number;
var newcode = [];
for (var i = 0; i<num; i++) {
newcode.push(this.cryptorandom(nums[0], nums[1]));
}
this.curcode.push(newcode);
}
}
},
watch: {
selected: function (newv, oldv) {
this.newrandom();
}
},
computed: {
phrase: function() {
var sentence = '';
for (var code of this.curcode) {
code = code.join(this.dicewarelist[this.selected].join);
sentence = sentence + this.dicewarelist[this.selected].list[code] + ' ';
}
sentence = sentence.substring(0, sentence.length-1);
return sentence;
//return this.dicewarelist[this.selected].list[this.curcode]
},
evaluated: function() {
var code = this.manual.split(',').join(this.dicewarelist[this.selected].join);
var word = this.dicewarelist[this.selected].list[code]
return word;
}
},
created: function () {
this.newrandom();
}
//dicewarelist[selected].list[curcode]
});