Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function lcm(x: BigInteger, y: BigInteger): BigInteger {
return bigInteger.lcm(x, y)
}
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),
};
}