forked from bc-game-project/verify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wheel.html
executable file
·184 lines (183 loc) · 7.89 KB
/
wheel.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
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Wheel verify</title>
<link rel="stylesheet" href="./lib/main.css">
<link rel="stylesheet" href="./lib/bootstrap/css/bootstrap.min.css">
<script src="./lib/vue.min.js"></script>
<script src="./lib/crypto-js.js"></script>
<script src="./lib/tools.js"></script>
</head>
<body>
<div id="app" class="main">
<h1 class="text-center pb-5">Wheel verify</h1>
<hr>
<form class="py-5">
<h2 class="text-center">Input</h2>
<div class="form-group">
<input :value="client_seed" @change="client_seed = $event.target.value" class="form-control" placeholder="Client Seed">
</div>
<div class="form-group">
<input :value="server_seed" @change="server_seed = $event.target.value" class="form-control" placeholder="Server Seed">
</div>
<div class="form-group">
<input :value="server_seed_hash" @change="server_seed_hash = $event.target.value" class="form-control" placeholder="Server Seed Hash">
</div>
<div class="form-group">
<input :value="nonce" @change="nonce = $event.target.value" class="form-control" placeholder="Nonce">
</div>
<div class="form-group">
<select class='form-control' v-model="risk">
<option>Low</option>
<option>Medium</option>
<option>High</option>
</select>
</div>
<div class="form-group">
<select class="form-control" v-model="segments">
<option>10</option>
<option>20</option>
<option>30</option>
<option>40</option>
<option>50</option>
</select>
</div>
</form>
<hr>
<form class="py-5">
<h2 class="text-center pb-5">Output</h2>
<div class="form-group">
<label>sha256(server_seed)</label>
<input class="form-control" readonly :value="sha256(server_seed)">
</div>
<div class="form-group">
<label>sha256(server_seed+client_seed+nonce)</label>
<input class="form-control" readonly :value="result_hash">
</div>
</form>
<hr>
<form class="py-5">
<h2 class="text-center pb-5">Results</h2>
<h5>Final Result</h5>
<div class="form-group" style="overflow-x: auto;">
<table class="table table-sm table-bordered">
<tbody>
<tr>
<td v-for="(item, index) in final_result" :key="index" :class="{'bg-success': Math.floor(numResult * segments) === index}">{{ index }}</td>
</tr>
<tr>
<td v-for="(item, index) in final_result" :key="index" :class="{'bg-success': Math.floor(numResult * segments) === index}">{{ item }}</td>
</tr>
</tbody>
</table>
</div>
<h5>SHA256(client_seed + server_seed + segments)</h5>
<div class="form-group" style="overflow-x: auto;">
<table class="table table-sm table-bordered">
<tbody>
<tr>
<td v-for="(item, index) in results.dec" :key="index" :class="{'text-muted': index > 3}">{{ item }}</td>
</tr>
<tr>
<td v-for="(item, index) in results.hex" :key="index" :class="{'text-muted': index > 3}">{{ item }}</td>
</tr>
</tbody>
</table>
</div>
<h5>Bytes to Number</h5>
<div class="form-group">
({{results.hex[0] + ', ' + results.hex[1] + ', ' + results.hex[2] + ', ' + results.hex[3]}}) -> [0, ... {{final_result.length - 1}}] = <span class="text-success">{{Math.floor(numResult * segments)}}</span>
<div><span> </span><span> {{Number(results.hex[0] / 256).toFixed(9)}} </span><span>({{results.hex[0]}} / (256 ^ 1))</span></div>
<div><span>+ </span><span>{{Number(results.hex[1] / (256 * 256)).toFixed(9)}} </span><span>({{results.hex[1]}} / (256 ^ 2))</span></div>
<div><span>+ </span><span>{{Number(results.hex[2] / (256 * 256 * 256)).toFixed(9)}} </span><span>({{results.hex[2]}} / (256 ^ 3))</span></div>
<div><span>+ </span><span>{{Number(results.hex[3] / (256 * 256 * 256 * 256)).toFixed(9)}} </span><span>({{results.hex[3]}} / (256 ^ 4))</span></div>
<div><span>= </span><span>{{numResult}} </span>(* {{segments}})</div>
<div><span>= </span><span class="text-success">{{Number(numResult * segments).toFixed(9)}}</span></div>
</div>
</form>
</div>
</body>
<script>
let qs = queryString();
var app = new Vue({
el: '#app',
data: {
/** inputs */
client_seed: qs.c,
server_seed: qs.s,
server_seed_hash: qs.h,
nonce: parseInt(qs.n) || 0,
risk: qs.r || 'Low',
segments: qs.t || 10,
payout: [
{segment:10, risk: 'Low', payouts: [1.5,1.2,1.2,1.2,0,1.2,1.2,1.2,1.2,0]},
{segment:20, risk: 'Low', payouts: [1.5,1.2,1.2,1.2,0,1.2,1.2,1.2,1.2,0,1.5,1.2,1.2,1.2,0,1.2,1.2,1.2,1.2,0]},
{segment:30, risk: 'Low', payouts: [1.5,1.2,1.2,1.2,0,1.2,1.2,1.2,1.2,0,1.5,1.2,1.2,1.2,0,1.2,1.2,1.2,1.2,0,1.5,1.2,1.2,1.2,0,1.2,1.2,1.2,1.2,0]},
{segment:40, risk: 'Low', payouts: [1.5,1.2,1.2,1.2,0,1.2,1.2,1.2,1.2,0,1.5,1.2,1.2,1.2,0,1.2,1.2,1.2,1.2,0,1.5,1.2,1.2,1.2,0,1.2,1.2,1.2,1.2,0,1.5,1.2,1.2,1.2,0,1.2,1.2,1.2,1.2,0]},
{segment:50, risk: 'Low', payouts: [1.5,1.2,1.2,1.2,0,1.2,1.2,1.2,1.2,0,1.5,1.2,1.2,1.2,0,1.2,1.2,1.2,1.2,0,1.5,1.2,1.2,1.2,0,1.2,1.2,1.2,1.2,0,1.5,1.2,1.2,1.2,0,1.2,1.2,1.2,1.2,0,1.5,1.2,1.2,1.2,0,1.2,1.2,1.2,1.2,0]},
{segment:10, risk: 'Medium', payouts: [0,1.9,0,1.5,0,2,0,1.5,0,3]},
{segment:20, risk: 'Medium', payouts: [1.5,0,2,0,2,0,2,0,1.5,0,3,0,1.8,0,2,0,2,0,2,0]},
{segment:30, risk: 'Medium', payouts: [1.5,0,1.5,0,2,0,1.5,0,2,0,2,0,1.5,0,3,0,1.5,0,2,0,2,0,1.7,0,4,0,1.5,0,2,0]},
{segment:40, risk: 'Medium', payouts: [2,0,3,0,2,0,1.5,0,3,0,1.5,0,1.5,0,2,0,1.5,0,3,0,1.5,0,2,0,2,0,1.6,0,2,0,1.5,0,3,0,1.5,0,2,0,1.5,0]},
{segment:50, risk: 'Medium', payouts: [2,0,1.5,0,2,0,1.5,0,3,0,1.5,0,1.5,0,2,0,1.5,0,3,0,1.5,0,2,0,1.5,0,2,0,2,0,1.5,0,3,0,1.5,0,2,0,1.5,0,1.5,0,5,0,1.5,0,2,0,1.5,0]},
{segment:10, risk: 'High', payouts: [0,0,0,0,0,0,0,0,0,9.9]},
{segment:20, risk: 'High', payouts: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,19.8]},
{segment:30, risk: 'High', payouts: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,29.7]},
{segment:40, risk: 'High', payouts: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,39.6]},
{segment:50, risk: 'High', payouts: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,49.5]}]
},
computed: {
result_hash () {
return this.sha256(this.server_seed + this.client_seed + this.nonce)
},
result_hash_list () {
return String(this.result_hash)
},
final_result () {
return this.payout.find(item => {
return (item.segment === Number(this.segments) && item.risk === this.risk)
}).payouts
},
results () {
let list = this.result_hash_list
let res = {
dec: [],
hex: []
}
for (let i = 0; i < list.length; i += 2) {
let dext = list[i] + list[i + 1]
let hext = parseInt(dext, 16)
res.dec.push(dext)
res.hex.push(hext)
}
return res
},
numResult () {
let num = 0
let list = this.results.hex
for (let i = 0; i < 4; i++) {
num += list[i] / Math.pow(256, (i + 1))
}
return num.toFixed(9)
}
},
created () {
console.log(this.result_hash_list)
},
methods: {
sha256 (value) {
return CryptoJS.SHA256(CryptoJS.enc.Utf8.parse(value));
},
sha512 (value) {
return CryptoJS.SHA512(CryptoJS.enc.Utf8.parse(value));
},
parseInt (value) {
return window.parseInt(value, 16);
},
}
});
</script>
</html>