Stage 1
Polynomial Selection
Choose polynomials with shared roots modulo n. The foundation of the algebraic structure.
Integer Factorization ยท Number Theory ยท Cryptography
An interactive guide to the fastest known algorithm for factoring large integers. Learn the mathematics. Explore the code. Run live demonstrations.
The Algorithm
Stage 1
Choose polynomials with shared roots modulo n. The foundation of the algebraic structure.
Stage 2
Find smooth relations using logarithmic sieve. The computational heart of GNFS.
Stage 3
Find dependencies using Gaussian elimination over GF(2). Sparse matrix techniques at scale.
Stage 4
Extract factors via congruence of squares. The algebraic payoff.
Interactive Learning
Read explanations alongside the actual Python source code that implements each concept.
Run real Python code in your browser. Experiment with different parameters and see results instantly.
Follow the algorithm through each stage with worked examples and visualizations.
Real Implementation
Every stage mirrors the real algorithms behind GNFS. Polynomial selection, logarithmic sieving, sparse matrix algebra, and algebraic square roots โ all in readable Python.
from gnfs import gnfs_factor
# Factor a semiprime
n = 8051
factors = gnfs_factor(n)
print(f"{n} = {factors[0]} ร {factors[1]}")
# โ 8051 = 83 ร 97