Post
Topic
Board Gambling
Re: bustabit.com -- The Social Gambling Game (formerly moneypot.com)
by
oryeger
on 05/12/2015, 11:31:06 UTC
Code:
function crashPointFromHash(serverSeed, clientSeed) {
  function divisible(hash, mod) {
    // We will read in 4 hex at a time, but the first chunk might be a bit smaller
    // So ABCDEFGHIJ should be chunked like  AB CDEF GHIJ
    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 hash = crypto.createHmac('sha256', serverSeed).update(clientSeed).digest('hex');

  /* In 1 of 101 games the game crashes instantly. */
  if (divisible(hash, 101))
     return 0;

  /* Use the most significant 52-bit from the hash
     to calculate the crash point */
  var h = parseInt(hash.slice(0,52/4),16);
  var e = Math.pow(2,52);

  return Math.floor((100 * e - h) / (e - h));
}

Or, in English:

To get from the sha256 hash to the crashpoint:

1) if the hash is exactly divisible by 101, crashpoint is 0x
2) otherwise crashpoint is (1 + 99e/(e-h)) / 100 to 2 decimal places, where e is 2^52 and h is the first 13 characters of the hash

Intuitively:

h ranges from 0 to 2^52-1.

If h is very small, e-h is very big, 99e/(e-h) is very close to 99, and the crashpoint is 1.00x.

If h is very big, e-h is small, 99e/(e-h) is very big, and the crashpoint is huge.

1) How can I divide a hash string by a number or use in in a math forumla? doest hashes have numerical value ?
2) the value of e is generated randomly or its derived out of something ?

if you can show me an exmaple of this calculation it would be great.

2) Also how are the odds of X multiplier to appear are calculated ?


RHavar: thank you for the explanation that part I understood but you made it even clearer.
I dont really know about how dice works at the backend but there is a method used by jackpot sites in the cs:go community where they used a secret string + a random generated number into a hash. they publish the hash and the secret before the game ends, once the game concludes you can take the winning number and the secret string and hash to check if it matches the hash that was published.
I can understand that this method is weak because you need to trust the site owners to generate true random numbers and strings.