You are reading a single comment by @sureshkm and its replies. Click here to read the full conversation.
  • Try something like this

    //RNG.js
    
    // Generates a 16 byte block of random numbers using AES
     //RNG.js
    function RNG(){
     this.key1=new Uint8Array(16);
     this.R=new Uint8Array(16);
     this.plain=new Uint8Array(16);
    }//end RNG
    
    RNG.prototype.random=function(A){
    var i;
    E.srand(E.hwRand()); //randomize
      for(i=0;i<16;i++)this.plain[i]=(Math.ran­dom()*256)%256;
      this.R=AES.encrypt(this.plain,this.key1)­;
      for(i=0;i<16;i++)A[i]=this.R[i];
    };//end random
    
    RNG.prototype.setup_random=function(){
     for(var i=0;i<16;i++){
      E.srand(E.hwRand());
      this.key1[i]=parseInt((Math.random()*256­),10);
     }
    };//end setup_random
    
    //exports = RNG;
    
    
    function testit(){
     var i;
     var A=new Uint8Array(16);
    // var W=new (require("RNG"))();
     var W=new RNG();
     W.setup_random();
      for(i=0;i<16;i++){
       W.random(A);
       console.log(A);
      }
    }
    
    testit();
    
About

Avatar for sureshkm @sureshkm started