async initializeRemotely(lengthOfOrder = 4096){
        return new Promise((resolve, reject)=>{

        https.get(`https://2ton.com.au/getprimes/random/${lengthOfOrder}`, 
                    (res)=>{
                        res.on('data', async (data)=>{
                            let readableData = data.toString('utf8');
                            let primes = JSON.parse(readableData);
                            this.p = bigInteger(primes.p.base10);
                            this.q = bigInteger(primes.q.base10);

                            //check Validity of primes:
                            if(this.q.multiply(2).add(1).compareTo(this.p))
                                reject(`The received primes are not in Safe form:
                                        p = ${primes.p.base10}, 
                                        q = ${primes.q.base10}`);
                            
                            if(!this.p.isProbablePrime())
                                reject('P is not prime: '+ primes.p.base10);
                            if(!this.q.isProbablePrime())
                                reject('q is not prime: ' + primes.q.base10);

                            //produce generator:
                            do{
                                let exponent = await bigIntManager.getInRange(this.p,3);
                                this.g = bigInteger[2].modPow(exponent, this.p);
                            }while(
                                this.g.modPow(this.q, this.p).notEquals(1) ||
                                this.g.modPow(2,this.p).equals(1) ||
                                this.p.prev().remainder(this.g).equals(0) ||
                                this.p.prev().remainder(this.g.modInv(this.p)).equals(0)
                            );

                            //Fill in the empty parameters:
                            await this.fillIn();

                            resolve(true);
                        })
                    }
        )
        })
    }
/**
     * it's better to choose the lengthes which are divided evenly by 8.
     * This method tries to connect to a remote DB and get the underlying group information 
     * then initialize the engine.
     * Unlike initialize() method which creates a thread and has an enormous cpu usage, this method
     * don't have any cpu usage but it's need a network connection!
     * @async
     * @param {allowedLengthes} lengthOfOrder indicate the length of Modulus Of Group in bit
     * @throws Will throw an error if there is no internet connection or received Information are
     * inconsistent.
     */
it's better to choose the lengthes which are divided evenly by 8.
This method tries to connect to a remote DB and get the underlying group information
then initialize the engine.
Unlike initialize() method which creates a thread and has an enormous cpu usage, this method
don't have any cpu usage but it's need a network connection.
@async
@param {allowedLengthes} lengthOfOrder indicate the length of Modulus Of Group in bit
@throws Will throw an error if there is no internet connection or received Information are
inconsistent.
it ' s better to choose the lengthes which are divided evenly by 8 . This method tries to connect to a remote DB and get the underlying group information then initialize the engine . Unlike initialize () method which creates a thread and has an enormous cpu usage this method don ' t have any cpu usage but it ' s need a network connection . @async @param { allowedLengthes } lengthOfOrder indicate the length of Modulus Of Group in bit @throws Will throw an error if there is no internet connection or received Information are inconsistent .
async initializeRemotely(lengthOfOrder = 4096){
        return new Promise((resolve, reject)=>{
        https.get(`https://2ton.com.au/getprimes/random/${lengthOfOrder}`, 
                    (res)=>{
                        res.on('data', async (data)=>{
                            let readableData = data.toString('utf8');
                            let primes = JSON.parse(readableData);
                            this.p = bigInteger(primes.p.base10);
                            this.q = bigInteger(primes.q.base10);
                            if(this.q.multiply(2).add(1).compareTo(this.p))
                                reject(`The received primes are not in Safe form:
                                        p = ${primes.p.base10}, 
                                        q = ${primes.q.base10}`);
                            if(!this.p.isProbablePrime())
                                reject('P is not prime: '+ primes.p.base10);
                            if(!this.q.isProbablePrime())
                                reject('q is not prime: ' + primes.q.base10);
                            do{
                                let exponent = await bigIntManager.getInRange(this.p,3);
                                this.g = bigInteger[2].modPow(exponent, this.p);
                            }while(
                                this.g.modPow(this.q, this.p).notEquals(1) ||
                                this.g.modPow(2,this.p).equals(1) ||
                                this.p.prev().remainder(this.g).equals(0) ||
                                this.p.prev().remainder(this.g.modInv(this.p)).equals(0)
                            );
                            await this.fillIn();
                            resolve(true);
                        })
                    }
        )
        })
    }
async initializeRemotely ( lengthOfOrder = 4096 ) { return new Promise ( ( resolve , reject ) => { https . get ( ` ${ lengthOfOrder } ` , ( res ) => { res . on ( 'data' , async ( data ) => { let readableData = data . toString ( 'utf8' ) ; let primes = JSON . parse ( readableData ) ; this . p = bigInteger ( primes . p . base10 ) ; this . q = bigInteger ( primes . q . base10 ) ; if ( this . q . multiply ( 2 ) . add ( 1 ) . compareTo ( this . p ) ) reject ( ` ${ primes . p . base10 } ${ primes . q . base10 } ` ) ; if ( ! this . p . isProbablePrime ( ) ) reject ( 'P is not prime: ' + primes . p . base10 ) ; if ( ! this . q . isProbablePrime ( ) ) reject ( 'q is not prime: ' + primes . q . base10 ) ; do { let exponent = await bigIntManager . getInRange ( this . p , 3 ) ; this . g = bigInteger [ 2 ] . modPow ( exponent , this . p ) ; } while ( this . g . modPow ( this . q , this . p ) . notEquals ( 1 ) || this . g . modPow ( 2 , this . p ) . equals ( 1 ) || this . p . prev ( ) . remainder ( this . g ) . equals ( 0 ) || this . p . prev ( ) . remainder ( this . g . modInv ( this . p ) ) . equals ( 0 ) ) ; await this . fillIn ( ) ; resolve ( true ) ; } ) } ) } ) }
it's better to choose the lengthes which are divided evenly by 8.
it ' s better to choose the lengthes which are divided evenly by 8 .
//check Validity of primes: //produce generator: //Fill in the empty parameters: