Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bc committed Oct 23, 2024
1 parent b65a0c7 commit 57b4619
Show file tree
Hide file tree
Showing 4 changed files with 207 additions and 143 deletions.
67 changes: 27 additions & 40 deletions classicdice_new.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,33 +48,25 @@ <h2 class="text-center pb-5">Output</h2>
<hr>
<form class="py-5">
<h2 class="text-center pb-5">Results</h2>
<div class="form-group">
<label>Final Result</label>
<input class="form-control" readonly :value="numResult">
</div>
<!-- <h5>hmac_sha256(client_seed:nonce, server_seed)</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, ... 4] = <span class="text-success">{{Math.floor(numResult * 100.01 * 100) / 100}}</span>
<div><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span> {{Number(results.hex[0] / 256).toFixed(9)}}&nbsp;&nbsp;&nbsp;&nbsp;</span><span>({{results.hex[0]}} / (256 ^ 1))</span></div>
<div><span>+&nbsp;&nbsp;&nbsp;&nbsp;</span><span>{{Number(results.hex[1] / (256 * 256)).toFixed(9)}}&nbsp;&nbsp;&nbsp;&nbsp;</span><span>({{results.hex[1]}} / (256 ^ 2))</span></div>
<div><span>+&nbsp;&nbsp;&nbsp;&nbsp;</span><span>{{Number(results.hex[2] / (256 * 256 * 256)).toFixed(9)}}&nbsp;&nbsp;&nbsp;&nbsp;</span><span>({{results.hex[2]}} / (256 ^ 3))</span></div>
<div><span>+&nbsp;&nbsp;&nbsp;&nbsp;</span><span>{{Number(results.hex[3] / (256 * 256 * 256 * 256)).toFixed(9)}}&nbsp;&nbsp;&nbsp;&nbsp;</span><span>({{results.hex[3]}} / (256 ^ 4))</span></div>
<div><span>=&nbsp;&nbsp;&nbsp;&nbsp;</span><span>{{numResult}}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>(* 10001 / 100)</div>
<div><span>=&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="text-success">{{Number(numResult * 100.01).toFixed(9)}}</span></div>
</div> -->
<h5>Final Result</h5>
<input class="form-control" readonly :value="numResult">
<h5 style="margin-top: 20px;">Calculation Process</h5>
<p>Using the formula `hmac_sha256(client_seed:nonce, server_seed)`,</p>
<p>We get the hash result:</p>
<p>`{{result_hash}}`.</p>
<br>
<ol>
<li>Take the first 15 characters, resulting in `{{baseHash}}`.</li>
<li>Convert this to decimal, which gives: `{{BigInt('0x' + baseHash)}}`.</li>
<li>Perform modulus 47(47 is fixed constant), and we get a remainder of {{index}}.</li>
<li>Starting from the index, take 14 characters, resulting in <span class="text-danger">`{{newHash}}`</span>.</li>
<li>Convert this to decimal, resulting in: `{{BigInt('0x' + newHash)}}`.</li>
<li>Divide by 8(8 is a fixed constant), resulting in: `{{BigInt('0x' + newHash) / BigInt(8)}}`.</li>
<li>Multiply by 2^-53(2^-53 is a fixed constant), resulting in: `{{Number(BigInt('0x' + newHash) / BigInt(8)) * Math.pow(2, -53)}}`.</li>
<li>Multiply by 10000(10000 is a fixed constant), resulting in: `{{Number(BigInt('0x' + newHash) / BigInt(8)) * Math.pow(2, -53) * 10000}}`.</li>
<li>Finally, take the integer part of the result, which gives: <span class="text-success">`{{numResult}}`</span>.</li>
</ol>
<div></div>
</form>
</div>
</body>
Expand All @@ -96,19 +88,14 @@ <h5>Bytes to Number</h5>
result_hash_list () {
return String(this.result_hash)
},
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
baseHash () {
return this.result_hash_list.substring(0, 15)
},
index () {
return Number(BigInt('0x' + this.result_hash_list.substring(0, 15)) % BigInt(47))
},
newHash () {
return this.result_hash_list.substring(this.index, this.index + 14)
},
numResult () {
return slideWindowNumber(this.result_hash_list, 10001) / 100;
Expand Down
27 changes: 23 additions & 4 deletions coinflip_new.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,34 @@ <h2 class="text-center">Input</h2>
<h2 class="text-center">Output</h2>
<form className="py-5">
{
Array(state.round).fill(1).map((item, index) => {
const hmacSha256Result = getHashString(state.serverSeed, state.clientSeed, state.nonce, index+1);
Array(state.round).fill(1).map((item, idx) => {
const hmacSha256Result = getHashString(state.serverSeed, state.clientSeed, state.nonce, idx+1);
const finalResult = getResult(hmacSha256Result);
const baseHash = hmacSha256Result.substring(0, 15);
const index = Number(BigInt('0x' + baseHash) % BigInt(47));
const newHash = hmacSha256Result.substring(index, index + 14);
return (
<div className="round-item" key={"round-" + index}>
<p className="t">Round: {index + 1}</p>
<div className="round-item" key={"round-" + idx}>
<p className="t">Round: {idx + 1}</p>
<div class="form-group">
<label>Final Result</label>
<input class="form-control" disabled value={finalResult} />
<h5 style={{ marginTop: 20 }}>Calculation Process</h5>
<p>Using the formula `hmac_sha256(client_seed:nonce, server_seed)`,</p>
<p>We get the hash result:</p>
<p>{hmacSha256Result}.</p>
<br />
<ol>
<li>Take the first 15 characters, resulting in {baseHash}.</li>
<li>Convert this to decimal, which gives: {BigInt('0x' + baseHash)}.</li>
<li>Perform modulus 47(47 is fixed constant), and we get a remainder of {index}.</li>
<li>Starting from the index, take 14 characters, resulting in <span className="text-danger">{newHash}</span>.</li>
<li>Convert this to decimal, resulting in: {BigInt('0x' + newHash)}.</li>
<li>Divide by 8(8 is a fixed constant), resulting in: {BigInt('0x' + newHash) / BigInt(8)}.</li>
<li>Multiply by 2^-53(2^-53 is a fixed constant), resulting in: {Number(BigInt('0x' + newHash) / BigInt(8)) * Math.pow(2, -53)}.</li>
<li>Multiply by 2(2 is a fixed constant), resulting in: {Number(BigInt('0x' + newHash) / BigInt(8)) * Math.pow(2, -53) * 2}.</li>
<li>Finally, take the integer part of the result, which gives: <span class="text-success">{finalResult}</span>.</li>
</ol>
</div>
</div>
)
Expand Down
226 changes: 130 additions & 96 deletions ringOfFortune_new.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
Expand All @@ -13,115 +14,148 @@
<script src="./lib/tools.js"></script>
<script src="./lib/utils.js"></script>
</head>

<body>

<div id="app" class="main">
<h1 class="text-center pb-5">Ring of fortune 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>hmac_sha256(client_seed:nonce, server_seed)</label>
<input class="form-control" readonly :value="result_hash">
</div>
</form>

<div id="app" class="main">
<h1 class="text-center pb-5">Ring of fortune 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">Results</h2>
<div class="form-group">
<label>Final Result</label>
<input class="form-control" readonly :value="numResult * 1000">
<div>
<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>hmac_sha256(client_seed:nonce, server_seed)</label>
<input class="form-control" readonly :value="result_hash">
</div>
</form>
<hr>
<form class="py-5">
<form class="py-5">
<h2 class="text-center pb-5">Results</h2>
<h5>Final Result</h5>
<input class="form-control" readonly :value="numResult * 1000">
<h5 style="margin-top: 20px;">Calculation Process</h5>
<p>Using the formula `hmac_sha256(client_seed:nonce, server_seed)`,</p>
<p>We get the hash result:</p>
<p>`{{result_hash}}`.</p>
<br>
<ol>
<li>Take the first 15 characters, resulting in `{{baseHash}}`.</li>
<li>Convert this to decimal, which gives: `{{BigInt('0x' + baseHash)}}`.</li>
<li>Perform modulus 47(47 is fixed constant), and we get a remainder of {{index}}.</li>
<li>Starting from the index, take 14 characters, resulting in <span class="text-danger">`{{newHash}}`</span>.
</li>
<li>Convert this to decimal, resulting in: `{{BigInt('0x' + newHash)}}`.</li>
<li>Divide by 8(8 is a fixed constant), resulting in: `{{BigInt('0x' + newHash) / BigInt(8)}}`.</li>
<li>Multiply by 2^-53(2^-53 is a fixed constant), resulting in: `{{Number(BigInt('0x' + newHash) /
BigInt(8)) * Math.pow(2, -53)}}`.</li>
<li>Finally, Multiply by 1000(1000 is a fixed constant), resulting in: `{{Number(BigInt('0x' + newHash) /
BigInt(8)) * Math.pow(2, -53) * 1000}}`.</li>
</ol>
<div></div>
</form>
<div :class="{'text-success': numResult * 1000 <= 495}">0~495 = {{range1}}</div>
<div :class="{'text-success': numResult * 1000 >= 496 && numResult * 1000 <= 825}">496~825 = {{range2}}</div>
<div :class="{'text-success': numResult * 1000 >= 826 && numResult * 1000 <= 990}">826~990 = {{range3}}</div>
<div :class="{'text-success': numResult * 1000 >= 991}">991~1000 = {{range4}}</div>
</div>
</div>
</form>
</div>
</div>
</body>
<script>
let qs = tools.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,
range1: qs.he === '4' ? '1.93x' : '2x',
range2: qs.he === '4' ? '2.90x' : '3x',
range3: qs.he === '4' ? '5.81x' : '6x',
range4: qs.he === '4' ? '96x' : '99x',
},
computed: {
result_hash () {
return this.hmac_sha256(this.client_seed + ':' + this.nonce, this.server_seed);
},
result_hash_list () {
return String(this.result_hash)
let qs = tools.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,
range1: qs.he === '4' ? '1.93x' : '2x',
range2: qs.he === '4' ? '2.90x' : '3x',
range3: qs.he === '4' ? '5.81x' : '6x',
range4: qs.he === '4' ? '96x' : '99x',
},
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)
computed: {
result_hash() {
return this.hmac_sha256(this.client_seed + ':' + this.nonce, this.server_seed);
},
result_hash_list() {
return String(this.result_hash)
},
baseHash() {
return this.result_hash_list.substring(0, 15)
},
index() {
return Number(BigInt('0x' + this.result_hash_list.substring(0, 15)) % BigInt(47))
},
newHash() {
return this.result_hash_list.substring(this.index, this.index + 14)
},
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() {
return slideWindowNumber(this.result_hash_list, 1000) / 1000;
}
return res
},
numResult () {
return slideWindowNumber(this.result_hash_list, 1000) / 1000;
}
},
watch: {
'this.numResult'() {
ga('send', 'event', 'ClassicDice', 'verify', this.server_seed, {metric0: this.client_seed, metric1: this.nonce})
}
},
created () {
console.log(this.result_hash_list)
},
methods: {
hmac_sha256 (msg, salt) {
return CryptoJS.HmacSHA256(msg, salt);
},
sha512 (value) {
return CryptoJS.SHA512(CryptoJS.enc.Utf8.parse(value));
},
sha256 (value) {
return CryptoJS.SHA256(CryptoJS.enc.Utf8.parse(value));
watch: {
'this.numResult'() {
ga('send', 'event', 'ClassicDice', 'verify', this.server_seed, { metric0: this.client_seed, metric1: this.nonce })
}
},
parseInt (value) {
return window.parseInt(value, 16);
created() {
console.log(this.result_hash_list)
},
}
});
methods: {
hmac_sha256(msg, salt) {
return CryptoJS.HmacSHA256(msg, salt);
},
sha512(value) {
return CryptoJS.SHA512(CryptoJS.enc.Utf8.parse(value));
},
sha256(value) {
return CryptoJS.SHA256(CryptoJS.enc.Utf8.parse(value));
},
parseInt(value) {
return window.parseInt(value, 16);
},
}
});
</script>

</html>
Loading

0 comments on commit 57b4619

Please sign in to comment.