fortuna based rng js

Solutions on MaxInterview for fortuna based rng js by the best coders in the world

showing results for - "fortuna based rng js"
Josefa
07 Oct 2018
1var os = require('os');
2if (os.platform() == 'win32') {  
3    if (os.arch() == 'ia32') {
4        var chilkat = require('@chilkat/ck-node11-win-ia32');
5    } else {
6        var chilkat = require('@chilkat/ck-node11-win64'); 
7    }
8} else if (os.platform() == 'linux') {
9    if (os.arch() == 'arm') {
10        var chilkat = require('@chilkat/ck-node11-arm');
11    } else if (os.arch() == 'x86') {
12        var chilkat = require('@chilkat/ck-node11-linux32');
13    } else {
14        var chilkat = require('@chilkat/ck-node11-linux64');
15    }
16} else if (os.platform() == 'darwin') {
17    var chilkat = require('@chilkat/ck-node11-macosx');
18}
19
20function chilkatExample() {
21
22    // All Chilkat classes can be unlocked at once at the beginning of a program
23    // by calling UnlockBundle.  It requires a Bundle unlock code.
24    var chilkatGlob = new chilkat.Global();
25    var success = chilkatGlob.UnlockBundle("Anything for 30-day trial.");
26    if (success !== true) {
27        console.log(chilkatGlob.LastErrorText);
28        return;
29    }
30
31    var fortuna = new chilkat.Prng();
32
33    // Before beginning to generate random data, 
34    // the PRNG (Pseudo Random Number Generator) should
35    // be seeded with real random data (also known as "entropy").
36
37    // Note: Accumulating real random data can be difficult
38    // and time-consuming to collect.  It is for this reason
39    // that pseudorandom data (i.e. a PRNG) is used.  The pseudorandom data generator
40    // is seeded with entropy.  In addition, new entropy can (and should)
41    // be periodically added as more pseudorandom data is generated.
42
43    // Get 32 bytes of system entropy.  On Linux/Unix systems, this reads
44    // from /dev/random.  On MS Windows systems, it uses the Crypto API's 
45    // CryptGenRandom function.
46    var strEntropy = fortuna.GetEntropy(32,"hex");
47    if (fortuna.LastMethodSuccess !== true) {
48        console.log(fortuna.LastErrorText);
49        return;
50    }
51
52    // Seed the PRNG with this entropy:
53    success = fortuna.AddEntropy(strEntropy,"hex");
54    if (success !== true) {
55        console.log(fortuna.LastErrorText);
56        return;
57    }
58
59    // Generate some random data:
60    var strRandHex = fortuna.GenRandom(16,"hex");
61    var strRandBase64 = fortuna.GenRandom(22,"base64");
62    var strRandBase58 = fortuna.GenRandom(32,"base58");
63
64    console.log("hex random bytes: " + strRandHex);
65    console.log("base64 random bytes: " + strRandBase64);
66    console.log("base58 random bytes: " + strRandBase58);
67
68}
69
70chilkatExample();
71
72