How to use the big-integer.gcd function in big-integer

To help you get started, we’ve selected a few big-integer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github thetrime / proscript2 / src / rational.js View on Github external
Rational.rationalize = function(n, d)
{
    if (d.isNegative())
    {
        n = n.negate();
        d = d.negate();
    }
    var s = BigInteger.gcd(n, d);
    if (s.isUnit())
        return new Rational(n, d);
    else if (s.equals(d))
    {
        var nn = n.divide(s);
        if (nn.isSmall)
            return nn.valueOf();
        return nn;
    }
    else
        return new Rational(n.divide(s), d.divide(s));

}
github gcanti / money-ts / src / BigInteger.ts View on Github external
export function gcd(x: BigInteger, y: BigInteger): BigInteger {
  return bigInteger.gcd(x, y)
}
github alikhil / sttp / src / rsa.js View on Github external
function generateRSAKeys() {

	var primeP = util.getRandomBigIntPrime(minPrimeNumber, maxPrimeNumber);
	var primeQ = util.getRandomBigIntPrime(minPrimeNumber, maxPrimeNumber);
	var N = primeP.times(primeQ);
	var F = primeQ.prev().times(primeP.prev());
	var E = bigInt(3674911);

	do {
		E = util.getRandomBigIntPrime(2, F.prev());

	} while(bigInt.gcd(E, F).notEquals(1));
	var D = E.modInv(F);

	var key = {};
	key.publicKey =  { N, E };
	key.privateKey = { N, E, D, P: primeP, Q: primeQ, F };	
	return key;
	
}
github denysdovhan / rsa-labwork / index.js View on Github external
static generate(keysize) {
    const e = bigInt(65537);
    let p;
    let q;
    let totient;
  
    do {
      p = this.randomPrime(keysize / 2);
      q = this.randomPrime(keysize / 2);
      totient = bigInt.lcm(
        p.prev(),
        q.prev()
      );
    } while (bigInt.gcd(e, totient).notEquals(1) || p.minus(q).abs().shiftRight(keysize / 2 - 100).isZero());

    return {
      e, 
      n: p.multiply(q),
      d: e.modInv(totient),
    };
  }