MartinBot

BustabitGameHashes.java

May 12th, 2016
809
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 KB | None | 0 0
  1. import java.io.UnsupportedEncodingException;
  2. import java.security.InvalidKeyException;
  3. import java.security.MessageDigest;
  4. import java.security.NoSuchAlgorithmException;
  5.  
  6. import javax.crypto.Mac;
  7. import javax.crypto.spec.SecretKeySpec;
  8.  
  9. public class BustabitGameHashes {
  10. public static final String clientSeed = "000000000000000007a9a31ff7f07463d91af6b5454241d5faf282e5e0fe1b3a";
  11.  
  12. public static boolean divisible(String hash, int mod) {
  13. // We will read in 4 hex at a time, but the first chunk might be a bit smaller
  14. // So ABCDEFGHIJ should be chunked like AB CDEF GHIJ
  15. int val = 0;
  16.  
  17. int o = hash.length() % 4;
  18. for (int i = o > 0 ? o - 4 : 0; i < hash.length(); i += 4) {
  19. val = ((val << 16) + Integer.parseInt(hash.substring(i, i+4), 16)) % mod;
  20. }
  21.  
  22. return val == 0;
  23. }
  24.  
  25. public static String bytesToHexString(byte[] byteData) {
  26. StringBuffer sb = new StringBuffer();
  27. for (int i = 0; i < byteData.length; i++) {
  28. sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
  29. }
  30.  
  31. return sb.toString();
  32. }
  33.  
  34. public static String getNextHash(String lastHash) throws NoSuchAlgorithmException {
  35. //return crypto.createHash('sha256').update(lastHash).digest('hex');
  36. MessageDigest md = MessageDigest.getInstance("SHA-256");
  37. md.update(lastHash.getBytes());
  38.  
  39. byte byteData[] = md.digest();
  40.  
  41. //convert the byte to hex format method 1
  42. return bytesToHexString(byteData);
  43. }
  44.  
  45. public static double crashPointFromHash(String hash) throws NoSuchAlgorithmException, UnsupportedEncodingException, InvalidKeyException {
  46. //hash = crypto.createHmac('sha256', hash).update(clientSeed).digest('hex');
  47. Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
  48. SecretKeySpec secret_key = new SecretKeySpec(hash.getBytes("UTF-8"), "HmacSHA256");
  49. sha256_HMAC.init(secret_key);
  50.  
  51. hash = bytesToHexString(sha256_HMAC.doFinal(clientSeed.getBytes("UTF-8")));
  52.  
  53. /* In 1 of 101 games the game crashes instantly. */
  54. if (divisible(hash, 101)) return 0;
  55.  
  56. /* Use the most significant 52-bit from the hash
  57. to calculate the crash point */
  58. //int h = parseInt(hash.slice(0,52/4),16);
  59. long h = Long.parseLong(hash.substring(0,52/4),16);
  60. double e = Math.pow(2,52);
  61.  
  62. return Math.floor((100 * e - h) / (e - h));
  63. }
  64.  
  65.  
  66. public static final String endHash = "a4d267ca9ca3941fc2bfd5c2ed77f3115bc7efb761d9824d237df5dfa427e496";
  67. public static final int sequenceLength = 50;
  68.  
  69.  
  70. public static void main(String args[]) {
  71. //System.out.println(dA + " " + dB + " " + dC);
  72. long start = System.currentTimeMillis();
  73.  
  74. double[] s = new double[sequenceLength];
  75. double crashPoint = 0;
  76. String hash = endHash;
  77.  
  78. try {
  79.  
  80. for (int i = (s.length-1); i >= 0; i--) {
  81. hash = getNextHash(hash);
  82. crashPoint = crashPointFromHash(hash);
  83. s[i] = crashPoint / 100;
  84. }
  85.  
  86. } catch (Exception e) {
  87. e.printStackTrace();
  88. }
  89.  
  90. // TODO: Do something with your generated crash points
  91.  
  92. System.out.println((System.currentTimeMillis()-start)/1000 + " Seconds");
  93. }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment