JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/sha3.js"></script>
<script src="http://www.leemon.com/crypto/BigInt.js"></script>
<body>
<h2><a href="https://ggdice.com">ggdice.com</a> fair check</h2>
<fieldset>
<legend>Data</legend>
<label for="secret">Secret:</label>
<input type="text" text="" name="secret" id="secret" placeholder="secret seed" />
<br />
<label for="userseed">User seed:</label>
<input type="text" text="" name="userseed" id="userseed" placeholder="user seed" />
<br />
<label for="nonce-1">Nonce start:</label>
<input type="text" text="" name="nonce-1" id="nonce-1" placeholder="Check rolls starting at this nonce" />
<br />
<label for="nonce-2">Nonce end:</label>
<input type="text" text="" name="nonce-2" id="nonce-2" placeholder="Check rolls till this nonce" />
<br /> <a href="#" id="check">Check</a>
</fieldset>
<br />
<fieldset>
<legend>Expected data</legend>
<label for="expected-hash">Secret hash:</label>
<input type="text" text="" name="expected-hash" id="expected-hash" readonly="true" />
<br />
<label for="roll">Rolls:</label>
<div id="roll" name="roll"></div>
</fieldset>
</body>
CSS
fieldset {
width: 560px;
}
input[type=text] {
width: 450px;
}
input[type=button] {
float: right;
}
#roll {
height: 10em;
overflow: auto;
width: 250px;
border: 1px solid;
}
a {
color: black;
font-weight: bold;
}
#check {
font-size: 14pt;
float: left;
width: 100%;
text-align: center;
padding: 6px 6px 0 6px;
margin: 0 auto;
}
label {
float: left;
text-align: right;
width: 90px;
margin-right: 6px;
}
JavaScript
$('#check').click(function (event) {
event.preventDefault();
var nonce_start = $('#nonce-1').val().trim();
var nonce_end = $('#nonce-2').val().trim();
var userseed = $('#userseed').val().trim();
var secret = $('#secret').val();
var secret_hash = CryptoJS.SHA3(secret, {
outputLength: 256
});
$('#expected-hash').val(secret_hash);
$('#roll').text('');
if (!userseed || Number(nonce_start) <= 0 || Number(nonce_end) <= Number(nonce_start)) {
$('#roll').text('no user seed or invalid nonce range');
return;
}
for (var i = Number(nonce_end) - 1; i >= Number(nonce_start); i--) {
var msg = secret + ":" + i + ":" + userseed;
var hash = CryptoJS.SHA3(msg, {
outputLength: 256
});
var result = modInt(str2bigInt(hash.toString(), 16, 0), 1000000);
console.log(i, result);
$('#roll').append('#' + i + ": " + result + "<br/>");
}
});