Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const getCoprime = (target) => {
const bits = Math.floor(Math.log2(target))
while (true) {
const lowerBound = bigInt(2).pow(bits-1).plus(1)
const size = bigInt(2).pow(bits).subtract(lowerBound)
let possible = lowerBound.plus(bigInt.rand(bits)).or(1)
const result = bigInt(possible)
if (possible.gt(bigInt(2).pow(1024))) return result
while(target > 0) {
[possible, target] = [target, possible.mod(target)]
}
if (possible.eq(bigInt(1))) return result
}
}