Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,151,848 members, 7,813,861 topics. Date: Tuesday, 30 April 2024 at 08:07 PM

Interprete This Javascript - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Interprete This Javascript (600 Views)

Can Someone Help Me With With This Javascript Exercise Please / Please Help With This Javascript Code / Help Me With This Javascript Problem (2) (3) (4)

(1) (Reply)

Interprete This Javascript by Brukx(m): 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)

Is It Advisable For Me To Learn Two Languages At A Time As A Beginner? / Please Webmasters Help / .

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 19
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.