прогноз кидка код

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

import java.math.

BigDecimal;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;

public class NextNumberCalculator {


public static void main(String[] args) {
String serverSeed = "server_seed";
String clientSeed = "client_seed";
int nonce = 1;

String string1 = nonce + ":" + serverSeed + ":" + nonce;


String string2 = nonce + ":" + clientSeed + ":" + nonce;

String hmac = calculateHMACSHA512(string1, string2);

int decimal = Integer.parseInt(hmac.substring(0, 8), 16);


BigDecimal result = new BigDecimal(decimal).divide(new
BigDecimal("429496.7295"), 0, BigDecimal.ROUND_HALF_UP);

System.out.println("The next number that will fall is: " +


result.intValue());
}

public static String calculateHMACSHA512(String data, String key) {


try {
SecretKeySpec secretKeySpec = new SecretKeySpec(key.getBytes(),
"HmacSHA512");
Mac mac = Mac.getInstance("HmacSHA512");
mac.init(secretKeySpec);
byte[] hmacData = mac.doFinal(data.getBytes());
StringBuilder sb = new StringBuilder();
for (byte b : hmacData) {
sb.append(String.format("%02x", b & 0xff));
}
return sb.toString();
} catch (NoSuchAlgorithmException | InvalidKeyException e) {
e.printStackTrace();
return "";
}
}
}

You might also like