Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. const serverHash = "d280d20edc8da0944f9893fe4e8e3b2010d197ef19f83856ebdd930866d54d04";
  2. const clientSeed = "732d81dc27d5fa9d";
  3. var nonce = 3000;
  4.  
  5. const roll_prime_dice = function (key, text) {
  6. // create HMAC using server seed as key and client seed as message
  7. const hash = crypto
  8. .createHmac('sha512', key)
  9. .update(text)
  10. .digest('hex');
  11.  
  12. let index = 0;
  13. const j = 5;
  14.  
  15. let lucky = parseInt(hash.substring(index * j, index * j + j), 16);
  16.  
  17. // keep grabbing characters from the hash while greater than
  18. while (lucky >= Math.pow(10, 6)) {
  19. index++;
  20. lucky = parseInt(hash.substring(index * j, index * j + j), 16);
  21.  
  22. // if we reach the end of the hash, just default to highest number
  23. if (index * 5 + 5 > 128) {
  24. lucky = 9999;
  25. break;
  26. }
  27. }
  28. // commented out to get the largest possible value.
  29. //lucky %= Math.pow(10, 4);
  30. //lucky /= Math.pow(10, 2);
  31.  
  32. return lucky;
  33. };
  34.  
  35. function generate(count) {
  36. var out = []
  37. for (var i=0; i < count; i++) {
  38. const e = jsData[Math.floor(Math.random()*500)]
  39. const str = e.blocksig + "" + e.tx + "0";
  40. // var buffer = createHash("sha256").update(str).digest()
  41. const n = roll_prime_dice(serverHash, `${clientSeed}-${nonce}`)
  42. //var n = randomN2(chainId, buffer, 0, Math.pow(2,32))
  43. nonce++;
  44. out.push(n)
  45. }
  46. return out;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement