-
Notifications
You must be signed in to change notification settings - Fork 26
/
index.html
130 lines (116 loc) · 3.2 KB
/
index.html
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
<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>scrypt-async-js demo</title>
<style>
html,
body {
font-family: sans-serif;
}
#out {
margin-top: 10px;
padding: 10px 5px;
color: #444;
line-height: 1.5;
}
#out small {
padding: 5px;
background-color: #eee;
}
#N {
margin-left: 10px;
color: #aaa;
}
</style>
</head>
<body>
<h1><a href="https://github.com/dchest/scrypt-async-js">scrypt-async-js</a> demo</h1>
<form onsubmit="calculate(); return false">
<p>
<label for="password">Password:</label>
<input id="password" name="password" type="text" value="password" size="32">
</p>
<p>
<label for="salt">Salt:</label>
<input id="salt" name="salt" type="text" value="salt" size="32">
</p>
<p>
<label for="interruptStep">interruptStep:</label>
<input id="interruptStep" name="interruptStep" type="text" value="0" size="8">
</p>
<p>
<label for="logN">logN:</label>
<input id="logN" name="logN" type="text" value="11" size="4"
onkeypress="updateN()" onkeyup="updateN()"
onblur="updateN()" onchange="updateN()" >
<span id="N">
</p>
<p>
<label for="r">r:</label>
<input id="r" name="r" type="text" value="8" size="4">
</p>
<p>
<label for="p">p:</label>
<input id="p" name="p" type="text" value="1" size="4">
</p>
<p>
<label for="encoding">Encoding:</label>
<select id="encoding" name="encoding">
<option value="hex" selected>hex</option>
<option value="base64">base64</option>
<option value="binary">binary</option>
</select>
</p>
<input type="submit" name="btn" value="Calculate" />
</form>
<div id="out"></div>
<script src="scrypt-async.js"></script>
<script>
var f = document.forms[0];
function updateN() {
var fN = document.querySelector('#N');
var logN = f.logN.value;
fN.innerHTML = 'N = ' + Math.pow(2, logN);
}
var getTime = (function () {
if (typeof performance !== "undefined") {
return performance.now.bind(performance);
}
return Date.now.bind(Date);
})();
function calculate() {
var btn = f.btn;
var out = document.querySelector('#out');
var password = f.password.value;
var salt = f.salt.value;
var interruptStep = f.interruptStep.value;
var logN = f.logN.value;
var r = f.r.value;
var p = f.p.value;
var encoding = f.encoding.value;
btn.disabled = true;
btn.value = 'Wait...';
window.setTimeout(function() {
try {
var t1 = getTime();
scrypt(password, salt, {
logN: logN,
r: r,
p: p,
dkLen: 32,
interruptStep: interruptStep,
encoding: encoding
},
function(res) {
var t2 = getTime() - t1;
out.innerHTML = 'Time: <b>'+t2+' ms</b><br>Result: <small>' + res + '</small>';
btn.disabled = false;
btn.value = 'Calculate';
});
} catch(ex) {
out.innerHTML = '<span style="color:red">error: ' + ex.message + '</span>'; btn.disabled = false; btn.value = 'Calculate';
} }); } updateN();
</script>
</body>
</html>