forked from bc-game-project/verify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
videopoker.html
executable file
·156 lines (155 loc) · 5.14 KB
/
videopoker.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
<!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>VideoPoker 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">VideoPoker 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>
</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>sha512(server_seed+client_seed+nonce)</label>
<input class="form-control" readonly :value="result_hash">
</div>
<hr>
</form>
<form class="py-5">
<h2 class="text-center pb-5">Results</h2>
<div class="form-group">
<div class="card-list">
<div :class="['cardbox', cardColor(item.card)]" v-for="(item, index) in card_list" :key="index">
<div class="card">
<div class="flower">{{cardFlower(item.card)}}</div>
<div class="point">{{cardPoint(item.card)}}</div>
</div>
</div>
</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,
allCards: [],
flower_list: ["♠", "♥", "♣", "♦"],
cards: []
},
computed: {
result_hash () {
return this.sha512(this.server_seed+this.client_seed+this.nonce);
},
result_hash_list () {
return String(this.result_hash).match(/.{2}/g);
},
results () {
let res = [];
let hexArr = this.result_hash_list;
for (let i=0, l=hexArr.length; i<l; i+=4) {
let num = this.parseInt(hexArr[i])/Math.pow(256, 1) + this.parseInt(hexArr[i+1])/Math.pow(256,2) + this.parseInt(hexArr[i+2])/Math.pow(256,3) + this.parseInt(hexArr[i+3])/Math.pow(256,4)
res.push(num);
}
return res;
},
card_list () {
let beginHash = String(this.result_hash);
return this.init(beginHash).splice(0, 10);
}
},
created () {
this.cards = " ,A,2,3,4,5,6,7,8,9,10,J,Q,K".split(",");
this.allCards = [161, 180, 199, 218, 162, 205, 181, 200, 219, 163, 182, 220, 201, 177, 196, 215, 170, 178, 221, 197, 216, 171, 179, 198, 172, 217, 193, 212, 167, 186, 194, 173, 213, 168, 187, 195, 214, 188, 169, 209, 164, 183, 202, 210, 189, 165, 184, 203, 211, 166, 204, 185]
},
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);
},
createCards(hash, times, cards, hashList) {
hashList.push(hash);
if (times <= 0) return
let h = hash;
this.allCards.forEach((c) => {
cards.push({ card: c, hash: h });
h = h.substring(1) + h.charAt(0);
});
hash = String(this.sha512(hash));
times--;
this.createCards(hash, times, cards, hashList);
},
init(hash, times) {
times = times || 1;
let cards = [];
let hashList = [];
this.createCards(hash, times, cards, hashList);
cards.sort(function (o1, o2) {
if (o1.hash < o2.hash) {
return -1;
} else if (o1.hash == o2.hash) {
return 0;
} else {
return 1;
}
})
return cards;
},
cardPoint (card) {
let point = this.cards[card % 16];
return point
},
cardFlower (card) {
let flowerIndex = (card & 240) / 16 - 10;
let flower = this.flower_list[flowerIndex];
return flower
},
cardColor (card) {
let flowerIndex = (card & 240) / 16 - 10;
let style = flowerIndex % 2 === 0 ? "black" : "red";
return style
}
}
})
</script>
</html>