I need a quick function rewrite from JavaScript to PHP. It has to work the same, i.e. produce the same result!
If you know both of these languages, this is a fast job for you.
Here's the JS script:
function divisible(hash, 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
var val = 0;
var o = [login to view URL] % 4;
for (var i = o > 0 ? o - 4 : 0; i < [login to view URL]; i += 4) {
val = ((val << 16) + parseInt([login to view URL](i, i+4), 16)) % mod;
}
return val === 0;
}
var serverSeed = '70d3c5c1df37d4e728e0c904adde41420cf50a4a39e7fee9fc2d84c753679170';
var clientSeed = '0xd8b8a187d5865a733680b4bf4d612afec9c6829285d77f438cd70695fb946801';
crashPointFromHash = function(serverSeed) {
var hash = [login to view URL]('sha256', serverSeed).update(clientSeed).digest('hex');
// 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
var h = parseInt([login to view URL](0,52/4),16);
var e = [login to view URL](2,52);
return [login to view URL]((100 * e - h) / (e - h));
};