Elliptic curves and the ECM algorithm
Sebastiano Tronto
ALTEN Scientific Software Evening
Part I: Numbers
What about division?
def extended_gcd(a, b):
if b == 0:
return a, 1, 0
g, x, y = extended_gcd(b, a % b)
return g, y, x - y*(a // b)
Division always works if \(N\) is a prime number!
Part II: Elliptic Curves
An elliptic curve is a curve with equation \[ y^2 = x^3+Ax+B \] Where \(A\) and \(B\) are numbers with \[4A^3+27B^2\neq 0\]
# Computes p+q on the elliptic curve y^2 = x^3 + Ax + B
def ec_sum(p: Point, q: Point, A: double) -> Point:
if p.is_zero:
return q
if q.is_zero:
return p
if p.x == q.x and p.y == -q.y:
return Point(is_zero = True)
if p.x != q.x:
k = (p.y - q.y) / (p.x - q.x)
else:
k = (3 * p.x**2 + A) / (p.y + q.y)
new_x = k**2 - p.x - q.x
new_y = k * (p.x - new_x) - p.y
return Point(x = new_x, y = new_y)
@dataclass
class Point:
x: int = 0
y: int = 0
is_zero: bool = False
Part III: The Elliptic Curve Factorization Method
Every positive integer can be written as the product of prime numbers
# Returns the list of prime factors of n
def factorize(n: int) -> list:
if n == 1:
return []
if is_prime(n):
return [n]
f = find_factor(n)
return factorize(f) + factorize(n//f)
def find_factor(n: int) -> int:
for i in range(2,floor(sqrt(n))+1):
if n % i == 0:
return i
To find a factor of \(n\):
Demo time!
git.tronto.net/ecmQ: Aren't we just computing the \(\operatorname{GCD}\) with random numbers?
A: Yes, but elliptic curve operations produce "good candidates" for these random numbers.
Q: Can we do the same without elliptic curves?
A: Yes, with Pollard's \(p-1\) Algorithm, but ECM is faster.
Q: Are there objects that are more complicated than elliptic curves and can make the method even faster?
A: Yes, there are higher-dimensional Abelian Varieties and other Algebraic Groups, but they are much harder (if not impossible) to implement efficiently.
More questions?
Drinks!