-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
130 lines (122 loc) · 4.49 KB
/
Copy pathindex.html
File metadata and controls
130 lines (122 loc) · 4.49 KB
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>
<title>Rolldice Verifier</title>
<script src="http://code.jquery.com/jquery.js"></script>
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/hmac-sha512.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/sha512.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/enc-base64-min.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/sha256.js"></script>
</head>
<body>
<div class="jumbotron">
<h1>Verifier</h1>
</div>
<div class="container">
<div class="well">
<center>
<h1>Rolldice Verifier</h1>
<div class="cont">
<!--<textarea class="form-control" id="randomize" placeholder="Paste from randomize textbox (Not for use with bets with a betid less than 145,000,000)"></textarea>
<br>or
<br>
<textarea class="form-control" id="id" placeholder="Bet ID (Optional, for use with bets with a betid less than 145,000,000)"></textarea>
<br>-->
<textarea class="form-control" id="ssh" placeholder="Hash of server seed"></textarea>
<br>
<textarea class="form-control" id="ss" placeholder="Server seed"></textarea>
<br>
<textarea class="form-control" id="cs" placeholder="Client seed"></textarea>
<br>
<input class="form-control" id="sn" placeholder="Starting nonce (>=1)" type="number"></input>
<br>
<input class="form-control" id="nb" placeholder="Number of Bets (>=1)" type="number"></input>
<br>
<button class="btn btn-default" id="verify">Verify</button>
</div>
<h2>Results:</h2>
<div class="cont">
<p id="results"></p>
</div>
</center>
</div>
</div>
<script type="text/javascript">
function check(event, ignoreInput) {
//var randomize = document.getElementById('randomize').value;
//var id = document.getElementById('id').value;
var ssh = document.getElementById('ssh').value;
var ss = document.getElementById('ss').value;
var cs = document.getElementById('cs').value;
var sn = document.getElementById('sn').value;
sn = parseInt(sn);
var nb = document.getElementById('nb').value;
nb = parseInt(nb);
/*if (!ignoreInput && randomize.length > 0) {
var pattern = /"(.+?)" "(.+?)" "(.+?)" "(.+?)"/;
if (pattern.test(randomize)) {
var result = pattern.exec(randomize);
document.getElementById('ss').value = result[1];
document.getElementById('ssh').value = result[2];
document.getElementById('cs').value = result[3];
document.getElementById('nb').value = result[4];
document.getElementById('sn').value = '1';
document.getElementById('randomize').value = '';
check(event, true);
return;
}
}*/
document.getElementById('results').innerHTML = '';
if (ssh != check.lastssh) { // Let's not repeat 'hash is correct' for the same hash.
ssh2 = CryptoJS.SHA256(ss);
if (ssh2 + '' == ssh) {
println('<span class="label label-success">Server secret hash is correct</span>');
} else {
println('<span class="label label-danger">Server hash check failed!</span>');
println('Purported hash: ' + ssh);
println('Actual hash: ' + ssh2);
}
}
for (j = sn + nb - 1; j >= sn; j--) {
var gen = ""
var ss2;
//if (id && id < 145000000) {
// gen = cs + ':' + j;
// ss2 = ss;
//} else {
gen = j + ':' + cs + ':' + j;
ss2 = j + ':' + ss + ':' + j;
//};
hash = CryptoJS.HmacSHA512(gen, ss2).toString(CryptoJS.enc.Hex);
i = 0;
roll = -1;
while (roll == -1) { // Non-reference implementation derived from the 'Fair?' description.
if (i == 25) {
l3 = hash.substring(125, 128);
l3p = l3.parseInt(l3, 16);
println('last 3: ' + l3 + ' as int: ' + l3p); // kept on because it's cool to get this far
roll = l3p / 10000;
} else {
f5 = hash.substring(5 * i, 5 + 5 * i);
f5p = parseInt(f5, 16);
//println(f5 + ' as int: ' + f5p);
if (f5p < 1000000) {
roll = f5p / 10000;
}
i++;
}
}
println(j + ': ' + roll);
}
check.lastssh = ssh;
}
function println(s) {
results = document.getElementById('results');
results.innerHTML = results.innerHTML + s + '<br>';
}
document.getElementById('verify').addEventListener('click', check);
</script>
</body>
</html>