Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.UnsupportedEncodingException;
- import java.security.InvalidKeyException;
- import java.security.MessageDigest;
- import java.security.NoSuchAlgorithmException;
- import javax.crypto.Mac;
- import javax.crypto.spec.SecretKeySpec;
- public class BustabitGameHashes {
- public static final String clientSeed = "000000000000000007a9a31ff7f07463d91af6b5454241d5faf282e5e0fe1b3a";
- public static boolean divisible(String hash, int 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
- int val = 0;
- int o = hash.length() % 4;
- for (int i = o > 0 ? o - 4 : 0; i < hash.length(); i += 4) {
- val = ((val << 16) + Integer.parseInt(hash.substring(i, i+4), 16)) % mod;
- }
- return val == 0;
- }
- public static String bytesToHexString(byte[] byteData) {
- StringBuffer sb = new StringBuffer();
- for (int i = 0; i < byteData.length; i++) {
- sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
- }
- return sb.toString();
- }
- public static String getNextHash(String lastHash) throws NoSuchAlgorithmException {
- //return crypto.createHash('sha256').update(lastHash).digest('hex');
- MessageDigest md = MessageDigest.getInstance("SHA-256");
- md.update(lastHash.getBytes());
- byte byteData[] = md.digest();
- //convert the byte to hex format method 1
- return bytesToHexString(byteData);
- }
- public static double crashPointFromHash(String hash) throws NoSuchAlgorithmException, UnsupportedEncodingException, InvalidKeyException {
- //hash = crypto.createHmac('sha256', hash).update(clientSeed).digest('hex');
- Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
- SecretKeySpec secret_key = new SecretKeySpec(hash.getBytes("UTF-8"), "HmacSHA256");
- sha256_HMAC.init(secret_key);
- hash = bytesToHexString(sha256_HMAC.doFinal(clientSeed.getBytes("UTF-8")));
- /* 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 */
- //int h = parseInt(hash.slice(0,52/4),16);
- long h = Long.parseLong(hash.substring(0,52/4),16);
- double e = Math.pow(2,52);
- return Math.floor((100 * e - h) / (e - h));
- }
- public static final String endHash = "a4d267ca9ca3941fc2bfd5c2ed77f3115bc7efb761d9824d237df5dfa427e496";
- public static final int sequenceLength = 50;
- public static void main(String args[]) {
- //System.out.println(dA + " " + dB + " " + dC);
- long start = System.currentTimeMillis();
- double[] s = new double[sequenceLength];
- double crashPoint = 0;
- String hash = endHash;
- try {
- for (int i = (s.length-1); i >= 0; i--) {
- hash = getNextHash(hash);
- crashPoint = crashPointFromHash(hash);
- s[i] = crashPoint / 100;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- // TODO: Do something with your generated crash points
- System.out.println((System.currentTimeMillis()-start)/1000 + " Seconds");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment