Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //REQUIRES https://github.com/emn178/js-sha3
- var hash = "0a6ae43a8a40074816f44cf23db029d3d4fc639dfb58925aa72b7ae03182c197";
- var secret = "639fd110d205287b5711070b8936019a30c073e5701ff67073b6edd166e223e6";
- var round_id = "435793";
- var day_of_month = "21";
- var crash_point = 1.09;
- var instant_crash_percentage = 4;
- var instant_crash_mode = 1;
- var outcome = keccak512.create();
- outcome.update(secret);
- outcome.update(round_id);
- outcome.update(day_of_month);
- var outcome_hash = outcome.hex();
- var calculateCrashPoint = function(outcome_hash) {
- var divisible = function divisible(hash, mod) {
- var val = 0;
- var o = hash.length % 4;
- for (var i = o > 0 ? o - 4 : 0; i < hash.length; i += 4) {
- val = ((val << 16) + parseInt(hash.substring(i, i + 4), 16)) %
- mod;
- }
- return val === 0;
- };
- var isInstantCrash = function (hash, percentage) {
- //we calculate a ticket and check if its less than the crash percentage
- var ticket = 100.0;
- var sub_hash = "";
- for (var i = 0; i < outcome_hash.length; ++i) {
- sub_hash += outcome_hash[i];
- if (sub_hash.length > 7)
- {
- var num = parseInt(sub_hash, 16);
- if ((num != NaN)) { ticket = (num % 1000001) / 10000.0;
- break;
- } sub_hash = "";
- }
- }
- return ticket < percentage ? true : false;
- };
- //we calculate if this round is instant crash with one of the following modes
- if ((instant_crash_mode === 0) && divisible(outcome_hash, 100.0 / instant_crash_percentage)) {
- return 0.0;
- }
- //new way of calculating instant crash so we can allow a lower percentage and more fairness
- else if ((instant_crash_mode === 1) && isInstantCrash(outcome_hash, instant_crash_percentage))
- {
- return 0.0;
- }
- // Use the most significant 52-bit from the hash to calculate the crash point
- var h = parseInt(outcome_hash.slice(0, 52 / 4), 16);
- var e = Math.pow(2, 52); return Math.floor((100 * e - h) / (e - h)) / 100.0;
- };
- console.log("calculated outcome:" + calculateCrashPoint(outcome_hash));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement