Package Exports
- @yaffle/ecm
- @yaffle/ecm/ecm.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@yaffle/ecm) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
- Lenstra elliptic-curve factorization
Usage:
npm install @yaffle/ecm
import ecm from './ecm.js';
console.log(ecm(2n**128n + 1n, true)); // 59649589127497217n, it takes about 2 seconds
function factors(n, count) {
const f = ecm(n, true);
return [f].concat(count === 2 ? [n / f] : factors(n / f, count - 1));
}
console.time();
console.log(factors(2n**2048n+1n, 5)); // ~3 minutes
console.timeEnd();
console.time();
console.log(factors(2n**1024n+1n, 4)); // ~2 days
console.timeEnd();
By default it searches for small factors only. The second argument unlimits the search to look for bigger factors. If a factor is not found 0n is returned.
Do not call for prime numbers.