passagemath-libecm

raw JSON →
10.8.4 verified Fri May 01 auth: no python

passagemath-libecm provides Python bindings to GMP-ECM for elliptic curve method (ECM) integer factorization. Version 10.8.4 supports Python 3.11-3.14. It is part of the passagemath ecosystem and is released on a regular cadence alongside other components.

pip install passagemath-libecm
error ImportError: cannot import name 'find_factor' from 'ecm'
cause Importing from the old 'ecm' package instead of 'passagemath.libecm'.
fix
Install passagemath-libecm and import from passagemath.libecm.
error AttributeError: module 'passagemath.libecm' has no attribute 'ECM'
cause Using an older version (pre-10.8.0) where the class name was 'ECMFactory' or simply a different layout.
fix
Upgrade to passagemath-libecm >=10.8.0, and use 'from passagemath.libecm import ECM'.
error TypeError: find_factor() got an unexpected keyword argument 'seed'
cause The 'seed' parameter was removed in version 10.8.3.
fix
Remove the seed argument; RNG is now automatic.
error ValueError: B1 must be less than B2
cause Stage 2 bound B2 must be larger than stage 1 bound B1.
fix
Ensure B2 > B1.
breaking The function signature changed between 10.8.2 and 10.8.3: the 'seed' parameter was removed and replaced by an internal RNG. Code using 'seed' will raise TypeError.
fix Remove the seed argument; RNG is now seeded automatically.
gotcha Do not import directly from 'ecm' or 'libecm' - the correct top-level module is 'passagemath.libecm'.
fix Use 'from passagemath.libecm import ...'
deprecated The 'curves' argument in ECM constructor is deprecated; use 'ncurves' instead.
fix Replace curves=10 with ncurves=10
gotcha Passing large numbers (over ~1000 digits) may hang or exhaust memory; tune B1/B2 appropriately.
fix Reduce B1 bounds or use the 'max_stage2_input' parameter.

Basic usage: attempt integer factorization with ECM using the find_factor function.

from passagemath.libecm import find_factor

# Factor a composite number
n = 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
B1 = 1000000
B2 = 100000000
result = find_factor(n, B1, B2)
print('Found factor:' if result else 'No factor found')