₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,330,346 members, 8,445,032 topics. Date: Tuesday, 14 July 2026 at 11:39 AM

Toggle theme

Interprete This Javascript - Programming - Nairaland

Nairaland ForumScience/TechnologyProgrammingInterprete This Javascript (699 Views)

1 Reply

Interprete This Javascript by Brukx(op): 5:36pm On Jun 20, 2020
The script below are the instructions an online casino uses in generating random floats. I don't understand J's, but with my knowledge of python I have an idea what's going on in the script except for the hashing (SHA512) part. Anyone with good js knowledge should come tell us what's happening here

// fill client seed, server seed and nonce with values from your roll details:
const clientSeed = "ZOujisvXvVe7fBedsQkWQaHwi5GiBFTz";
const serverSeed = "Wgh5dqFCnKihl07hluONRzs8wkDJSaBMuAwuviWNlQjPrFsonsYYNe0irlz0ld00";
const nonce = 127;

console.log(roll(serverSeed, clientSeed, nonce));

// ------------ don't edit below this line ------------
function roll(serverSeed, clientSeed, nonce) {
const crypto = require('crypto');
const text = clientSeed + ':' + nonce;
const hash = crypto.createHmac('sha512', serverSeed).update(text).digest('hex');
const hashLength = hash.length;
const step = 5;
let index = 0;
let rollResult;

do {
const start = index * step;
const end = start + step;

if (end > hashLength) {
rollResult = 9999;
break;
}

rollResult = parseInt(hash.substring(start, end), 16);

index++;
} while (rollResult >= Math.pow(10, 6));

rollResult %= Math.pow(10, 4);
rollResult /= Math.pow(10, 2);

return rollResult;
}
Re: Interprete This Javascript by Edipet(m): 6:55pm On May 25, 2023
Brukx:
The script below are the instructions an online casino uses in generating random floats. I don't understand J's, but with my knowledge of python I have an idea what's going on in the script except for the hashing (SHA512) part. Anyone with good js knowledge should come tell us what's happening here

// fill client seed, server seed and nonce with values from your roll details:
const clientSeed = "ZOujisvXvVe7fBedsQkWQaHwi5GiBFTz";
const serverSeed = "Wgh5dqFCnKihl07hluONRzs8wkDJSaBMuAwuviWNlQjPrFsonsYYNe0irlz0ld00";
const nonce = 127;

console.log(roll(serverSeed, clientSeed, nonce));

// ------------ don't edit below this line ------------
function roll(serverSeed, clientSeed, nonce) {
const crypto = require('crypto');
const text = clientSeed + ':' + nonce;
const hash = crypto.createHmac('sha512', serverSeed).update(text).digest('hex');
const hashLength = hash.length;
const step = 5;
let index = 0;
let rollResult;

do {
const start = index * step;
const end = start + step;

if (end > hashLength) {
rollResult = 9999;
break;
}

rollResult = parseInt(hash.substring(start, end), 16);

index++;
} while (rollResult >= Math.pow(10, 6));

rollResult %= Math.pow(10, 4);
rollResult /= Math.pow(10, 2);

return rollResult;
}
omor. Looks like something that vi should know but I don't know it
Re: Interprete This Javascript by niel63(m): 9:49pm On May 25, 2023
Js is an interpreted language. cheesy
Wetin we wan interprete again? Everything you see there is as it is... literally in plain language. Abi na the modulo dey consfuse you? The conditionals or the crypto package and its methods?

The place they said dont edit, no mind them. You can edit the to your choice of naming except for some of the reserved keywords and method.
1 Reply

HELP With This Javascript ProblemCan Someone Help Me With With This Javascript Exercise PleaseHelp Me With This Javascript Problem234

Get The Latest Php Investment Script With Flexible Payment GatewayRant On Operating System Stuff.Hackers, Share The Biggest Ever Hack You're Carried Out