Server code


SUBMITTED BY: Guest

DATE: Oct. 1, 2014, 8:06 a.m.

FORMAT: Text only

SIZE: 1.5 kB

HITS: 1099

  1. //the seed pair itself
  2. var clientSeed = "your client seed"; //dont forget to exclude the dash and the nonce!
  3. var serverSeed = "your server seed";
  4. //bet made with seed pair (excluding current bet)
  5. var nonce = 0;
  6. //crypto lib for hmac function
  7. var crypto = require('crypto');
  8. var roll = function(key, text) {
  9. //create HMAC using server seed as key and client seed as message
  10. var hash = crypto.createHmac('sha512', key).update(text).digest('hex');
  11. var index = 0;
  12. var lucky = parseInt(hash.substring(index * 5, index * 5 + 5), 16);
  13. //keep grabbing characters from the hash while greater than
  14. while (lucky >= Math.pow(10, 6)) {
  15. index++;
  16. lucky = parseInt(hash.substring(index * 5, index * 5 + 5), 16);
  17. //if we reach the end of the hash, just default to highest number
  18. if (index * 5 + 5 > 128) {
  19. lucky = 99.99;
  20. break;
  21. }
  22. }
  23. lucky %= Math.pow(10, 4);
  24. lucky /= Math.pow(10, 2);
  25. return lucky;
  26. }
  27. console.log(roll(serverSeed, clientSeed+'-'+nonce));

comments powered by Disqus