Advertisement
peterspike12

Java

Jan 14th, 2018
441
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. /*MasterBugPatch
  2. Feel free to send me bits ;) https://www.bustabit.com/user/masterbugpatch
  3. */
  4. function runCheck(){
  5. var gamesToCheck = parseInt(document.getElementById("gamesInput").value);
  6. var hash = document.getElementById("hashInput").value;
  7. var crashToCheck = parseInt(document.getElementById("crashInput").value);
  8.  
  9. var intervalsBetweenCrashes = [];
  10. var waitingForFirstCrash = true;
  11. var gamesTillCrash = 0;
  12. var mostRecentCrash = 0;
  13. for(var n = 0; n != gamesToCheck;n++){
  14. var gameCrash = crashPointFromHash(hash);
  15. if(gameCrash >= crashToCheck){
  16. if(waitingForFirstCrash){
  17. waitingForFirstCrash = false;
  18. mostRecentCrash = gamesTillCrash;
  19. }else{
  20. intervalsBetweenCrashes.push(gamesTillCrash);
  21. }
  22. gamesTillCrash = 0;
  23. }else{
  24. gamesTillCrash++;
  25. }
  26. hash = genGameHash(hash);
  27. }
  28. var result = "Last " + crashToCheck + "x occured " + mostRecentCrash + " games from the hash<br>Intervals between " + crashToCheck + "x crashes within last " + gamesToCheck + " games below..." + "<br>" + intervalsBetweenCrashes;
  29. document.getElementById("status").innerHTML = result;
  30. }
  31.  
  32. function requestCheck(){
  33. document.getElementById("status").innerHTML = "Checking...";
  34. setTimeout(runCheck, 0);
  35. }
  36.  
  37. /*ALL CODE BELOW THIS LINE IS FROM https://jsfiddle.net/1L1uqcgv/6/embedded/result/*/
  38. function divisible(hash, mod) {
  39. var val = 0;
  40.  
  41. var o = hash.length % 4;
  42. for (var i = o > 0 ? o - 4 : 0; i < hash.length; i += 4) {
  43. val = ((val << 16) + parseInt(hash.substring(i, i+4), 16)) % mod;
  44. }
  45.  
  46. return val === 0;
  47. }
  48.  
  49. function genGameHash(serverSeed) {
  50. return CryptoJS.SHA256(serverSeed).toString()
  51. };
  52.  
  53.  
  54. function hmac(key, v) {
  55. var hmacHasher = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, key);
  56. return hmacHasher.finalize(v).toString();
  57. }
  58.  
  59. function crashPointFromHash(serverSeed) {
  60. // see: provably fair seeding event
  61. var hash = hmac(serverSeed, '000000000000000007a9a31ff7f07463d91af6b5454241d5faf282e5e0fe1b3a');
  62.  
  63. // In 1 of 101 games the game crashes instantly.
  64. if (divisible(hash, 101))
  65. return 0;
  66.  
  67. // Use the most significant 52-bit from the hash to calculate the crash point
  68. var h = parseInt(hash.slice(0,52/4),16);
  69. var e = Math.pow(2,52);
  70.  
  71. return (Math.floor((100 * e - h) / (e - h))/100).toFixed(2);
  72. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement