Escolar Documentos
Profissional Documentos
Cultura Documentos
CARAMEL
/* */ C,A,
/* */ R,a,
/* */ M,E,
L,i=
5,e,
d[5],Q[999 ]={0};main(N ){for
(;i--;e=scanf("%" "d",d+i));for(A =*d;
++i<A ;++Q[ i*i% A],R= i[Q]?
R:i); for(;i --;) for(M =A;M
--;N +=!M*Q [E%A ],e+= Q[(A
+E*E- R*L* L%A) %A]) for(
E=i,L=M,a=4;a;C= i*E+R*M*L,L=(M*E +i*L)
%A,E=C%A+a --[d]);printf ("%d"
"\n",
(e+N*
N)/2
/* cc caramel.c; echo f3 f2 f1 f0 p | ./a.out */ -A);}
Why factor?
I Cryptography:
• Integer factorization is a (supposedly) difficult problem, but
integer multiplication is not
• E.g., basis for the security of the
RSA public-key cryptosystem:
→ private key: large primes p and q
→ public key: N = p · q
• Key length recommendations
• Break weak instances of RSA (short keys)
I Number theory:
• Cunningham tables: factorizations
X of b n ± 1
• Aliquot sequences: sn+1 = d − sn
• etc. d|sn
I Number theory:
• Cunningham tables: factorizations
X of b n ± 1
• Aliquot sequences: sn+1 = d − sn
• etc. d|sn
I For fun ,
Jérémie Detrey — Factoring integers with CADO-NFS 1 / 22
Factorization algorithms (I)
→ subexponential complexity!
→ subexponential complexity!
I QS and MPQS:
• YAFU [Buhrow]:
http://yafu.sourceforge.net/
I QS and MPQS:
• YAFU [Buhrow]:
http://yafu.sourceforge.net/
Z[X ]
Z[X ]
Z[X ]
X 7→ X mod f1
Z[X ]/(f1(X ))
Z[X ]
X 7→ α1
Z[α1] ⊂ OQ(α1)
Z[X ]
X 7→ α1 X 7→ α2
Z[X ]
X 7→ α1 X 7→ α2
Z[α1] Z[α2]
Z[X ]
X 7→ α1 X 7→ α2
Z[α1] Z[α2]
α1 7→ m mod N α2 7→ m mod N
Z/N Z
Jérémie Detrey — Factoring integers with CADO-NFS 8 / 22
The Number Field Sieve
I Based on Fermat’s factoring method (congruence of squares):
• Find two integers x and y such that x 2 ≡ y 2 (mod N)
• With good probability, gcd(x ± y , N) gives a non-trivial factor of N
I Obtain such equalities through two number fields
• f1 and f2 ∈ Z[X ] two polynomials, irreducible and coprime over Q
• αi root of fi : Q(αi ) is an algebraic number field
• f1 and f2 chosen such that they have a common root m in Z/N Z
Γ(X ) ∈ Z[X ]
X 7→ α1 X 7→ α2
Z[α1] Z[α2]
α1 7→ m mod N α2 7→ m mod N
Z/N Z
Jérémie Detrey — Factoring integers with CADO-NFS 8 / 22
The Number Field Sieve
I Based on Fermat’s factoring method (congruence of squares):
• Find two integers x and y such that x 2 ≡ y 2 (mod N)
• With good probability, gcd(x ± y , N) gives a non-trivial factor of N
I Obtain such equalities through two number fields
• f1 and f2 ∈ Z[X ] two polynomials, irreducible and coprime over Q
• αi root of fi : Q(αi ) is an algebraic number field
• f1 and f2 chosen such that they have a common root m in Z/N Z
Γ(X ) ∈ Z[X ]
X 7→ α1 X 7→ α2
α1 7→ m mod N α2 7→ m mod N
Z/N Z
Jérémie Detrey — Factoring integers with CADO-NFS 8 / 22
The Number Field Sieve
I Based on Fermat’s factoring method (congruence of squares):
• Find two integers x and y such that x 2 ≡ y 2 (mod N)
• With good probability, gcd(x ± y , N) gives a non-trivial factor of N
I Obtain such equalities through two number fields
• f1 and f2 ∈ Z[X ] two polynomials, irreducible and coprime over Q
• αi root of fi : Q(αi ) is an algebraic number field
• f1 and f2 chosen such that they have a common root m in Z/N Z
Γ(X ) ∈ Z[X ]
X 7→ α1 X 7→ α2
α1 7→ m mod N α2 7→ m mod N
Z/N Z
Jérémie Detrey — Factoring integers with CADO-NFS 8 / 22
The Number Field Sieve
I Based on Fermat’s factoring method (congruence of squares):
• Find two integers x and y such that x 2 ≡ y 2 (mod N)
• With good probability, gcd(x ± y , N) gives a non-trivial factor of N
I Obtain such equalities through two number fields
• f1 and f2 ∈ Z[X ] two polynomials, irreducible and coprime over Q
• αi root of fi : Q(αi ) is an algebraic number field
• f1 and f2 chosen such that they have a common root m in Z/N Z
Γ(X ) ∈ Z[X ]
X 7→ α1 X 7→ α2
α1 7→ m mod N α2 7→ m mod N
Z/N Z
⇒ γ1(m)2 ≡ γ2(m)2 mod N
Jérémie Detrey — Factoring integers with CADO-NFS 8 / 22
The Number Field Sieve
I How can one find such a polynomial Γ(X )?
Z[X ]
X 7→ α1 X 7→ α2
Z[α1] Z[α2]
α1 7→ m mod N α2 7→ m mod N
Z/N Z
Z[X ]
X 7→ α1 X 7→ α2
Z[α1] Z[α2]
α1 7→ m mod N α2 7→ m mod N
Z/N Z
Z[X ]
X 7→ α1 X 7→ α2
Z[α1] Z[α2]
α1 7→ m mod N α2 7→ m mod N
Z/N Z
a − bX ∈ Z[X ]
X 7→ α1 X 7→ α2
Z[α1] Z[α2]
α1 7→ m mod N α2 7→ m mod N
Z/N Z
a − bX ∈ Z[X ]
X 7→ α1 X 7→ α2
α1 7→ m mod N α2 7→ m mod N
Z/N Z
a − bX ∈ Z[X ]
X 7→ α1 X 7→ α2
α1 7→ m mod N α2 7→ m mod N
Z/N Z
a − bX ∈ Z[X ]
X 7→ α1 X 7→ α2
a − bX ∈ Z[X ]
X 7→ α1 X 7→ α2
(a,b)∈S
(a,b)∈S
I Example:
(a,b)∈S
I Example:
2 2 4
(a1, b1) : a1 − b1α1 = p1,1 p1,2 p1,3 a1 − b1α2 = p2,1 p2,2
(a,b)∈S
I Example:
2 2 4
(a1, b1) : a1 − b1α1 = p1,1 p1,2 p1,3 a1 − b1α2 = p2,1 p2,2
3
(a2, b2) : a2 − b2α1 = p1,2 p1,3 a2 − b2α2 = p2,1 p2,2 p2,3
(a,b)∈S
I Example:
2 2 4
(a1, b1) : a1 − b1α1 = p1,1 p1,2 p1,3 a1 − b1α2 = p2,1 p2,2
3
(a2, b2) : a2 − b2α1 = p1,2 p1,3 a2 − b2α2 = p2,1 p2,2 p2,3
2 3
(a3, b3) : a3 − b3α1 = p1,1 p1,2 p1,3 a3 − b3α2 = p2,2 p2,3
(a,b)∈S
I Example:
2 2 4
(a1, b1) : a1 − b1α1 = p1,1 p1,2 p1,3 a1 − b1α2 = p2,1 p2,2
3
(a2, b2) : a2 − b2α1 = p1,2 p1,3 a2 − b2α2 = p2,1 p2,2 p2,3
2 3
(a3, b3) : a3 − b3α1 = p1,1 p1,2 p1,3 a3 − b3α2 = p2,2 p2,3
2
(a4, b4) : a4 − b4α1 = p1,1 p1,3 a4 − b4α2 = p2,1 p2,2 p2,3
(a,b)∈S
I Example:
2 2 4
(a1, b1) : a1 − b1α1 = p1,1 p1,2 p1,3 a1 − b1α2 = p2,1 p2,2
3
(a2, b2) : a2 − b2α1 = p1,2 p1,3 a2 − b2α2 = p2,1 p2,2 p2,3
2 3
(a3, b3) : a3 − b3α1 = p1,1 p1,2 p1,3 a3 − b3α2 = p2,2 p2,3
2
(a4, b4) : a4 − b4α1 = p1,1 p1,3 a4 − b4α2 = p2,1 p2,2 p2,3
(a,b)∈S
I Example:
2 2 4
(a1, b1) : a1 − b1α1 = p1,1 p1,2 p1,3 a1 − b1α2 = p2,1 p2,2
3
(a2, b2) : a2 − b2α1 = p1,2 p1,3 a2 − b2α2 = p2,1 p2,2 p2,3
2 3
(a3, b3) : a3 − b3α1 = p1,1 p1,2 p1,3 a3 − b3α2 = p2,2 p2,3
2
(a4, b4) : a4 − b4α1 = p1,1 p1,3 a4 − b4α2 = p2,1 p2,2 p2,3
4 4 4 4 6 2
Y Y
(ai − bi α1 ) = p1,1 p1,2 p1,3 (ai − bi α2 ) = p2,1 p2,2 p2,3
i∈{1,2,4} i∈{1,2,4}
(a,b)∈S
I Example:
2 2 4
(a1, b1) : a1 − b1α1 = p1,1 p1,2 p1,3 a1 − b1α2 = p2,1 p2,2
3
(a2, b2) : a2 − b2α1 = p1,2 p1,3 a2 − b2α2 = p2,1 p2,2 p2,3
2 3
(a3, b3) : a3 − b3α1 = p1,1 p1,2 p1,3 a3 − b3α2 = p2,2 p2,3
2
(a4, b4) : a4 − b4α1 = p1,1 p1,3 a4 − b4α2 = p2,1 p2,2 p2,3
4 4 4 4 6 2
Y Y
(ai − bi α1 ) = p1,1 p1,2 p1,3 (ai − bi α2 ) = p2,1 p2,2 p2,3
i∈{1,2,4} i∈{1,2,4}
(a,b)∈S
I Example:
2 2 4
(a1, b1) : a1 − b1α1 = p1,1 p1,2 p1,3 a1 − b1α2 = p2,1 p2,2
3
(a2, b2) : a2 − b2α1 = p1,2 p1,3 a2 − b2α2 = p2,1 p2,2 p2,3
2 3
(a3, b3) : a3 − b3α1 = p1,1 p1,2 p1,3 a3 − b3α2 = p2,2 p2,3
2
(a4, b4) : a4 − b4α1 = p1,1 p1,3 a4 − b4α2 = p2,1 p2,2 p2,3
(a,b)∈S
I Example:
(a1, b1) : a1 − b1α1 ≡ ( 2 1 2 ) a1 − b1α2 ≡ ( 1 4 0 )
3
(a2, b2) : a2 − b2α1 = p1,2 p1,3 a2 − b2α2 = p2,1 p2,2 p2,3
2 3
(a3, b3) : a3 − b3α1 = p1,1 p1,2 p1,3 a3 − b3α2 = p2,2 p2,3
2
(a4, b4) : a4 − b4α1 = p1,1 p1,3 a4 − b4α2 = p2,1 p2,2 p2,3
(a,b)∈S
I Example:
(a1, b1) : a1 − b1α1 ≡ ( 2 1 2 ) a1 − b1α2 ≡ ( 1 4 0 )
(a2, b2) : a2 − b2α1 ≡ ( 0 3 1 ) a2 − b2α2 ≡ ( 1 1 1 )
(a3, b3) : a3 − b3α1 ≡ ( 1 2 1 ) a3 − b3α2 ≡ ( 0 1 3 )
(a4, b4) : a4 − b4α1 ≡ ( 2 0 1 ) a4 − b4α2 ≡ ( 2 1 1 )
(a,b)∈S
I Example:
(a1, b1) : a1 − b1α1 ≡ ( 0 1 0 ) a1 − b1α2 ≡ ( 1 0 0 )
(a2, b2) : a2 − b2α1 ≡ ( 0 1 1 ) a2 − b2α2 ≡ ( 1 1 1 )
(a3, b3) : a3 − b3α1 ≡ ( 1 0 1 ) a3 − b3α2 ≡ ( 0 1 1 )
(a4, b4) : a4 − b4α1 ≡ ( 0 0 1 ) a4 − b4α2 ≡ ( 0 1 1 )
(a,b)∈S
I Example:
(a1, b1) : a1 − b1α1 ≡ ( 0 1 0 ) a1 − b1α2 ≡ ( 1 0 0 )
(a2, b2) : a2 − b2α1 ≡ ( 0 1 1 ) a2 − b2α2 ≡ ( 1 1 1 )
(a3, b3) : a3 − b3α1 ≡ ( 1 0 1 ) a3 − b3α2 ≡ ( 0 1 1 )
(a4, b4) : a4 − b4α1 ≡ ( 0 0 1 ) a4 − b4α2 ≡ ( 0 1 1 )
Y Y
(ai − bi α1 ) ≡ ( 0 0 0 ) (ai − bi α2 ) ≡ ( 0 0 0 )
i∈{1,2,4} i∈{1,2,4}
a − bX ∈ Z[X ]
X 7→ α1 X 7→ α2
a − bX ∈ Z[X ]
X 7→ α1 X 7→ α2
×Y
j
e
p1,j1,j = a − bα1 ∈ Z[α1]
α1 7→ m mod N α2 7→ m mod N
×
Z[α2] 3 a − bα2 =
Y
j
e
p2,j2,j
Z/N Z
Jérémie Detrey — Factoring integers with CADO-NFS 11 / 22
The Number Field Sieve
I Slight problem: no unique factorization of numbers in Z[αi ] or OQ(αi )
I However, OQ(αi ) is a Dedekind domain: unique factorization of ideals
into products of prime ideals
a − bX ∈ Z[X ]
X 7→ α1 X 7→ α2
Z[α1] Z[α2]
α1 7→ m mod N α2 7→ m mod N
Z/N Z
Jérémie Detrey — Factoring integers with CADO-NFS 11 / 22
The Number Field Sieve
I Slight problem: no unique factorization of numbers in Z[αi ] or OQ(αi )
I However, OQ(αi ) is a Dedekind domain: unique factorization of ideals
into products of prime ideals
a − bX ∈ Z[X ]
X 7→ α1 X 7→ α2
α1 7→ m mod N α2 7→ m mod N
Z/N Z
Jérémie Detrey — Factoring integers with CADO-NFS 11 / 22
The Number Field Sieve
I Slight problem: no unique factorization of numbers in Z[αi ] or OQ(αi )
I However, OQ(αi ) is a Dedekind domain: unique factorization of ideals
into products of prime ideals
• Prime ideals p of Z[αi ] given by integers (p, r ) such that p is prime
and fi (r ) ≡ 0 (mod p)
a − bX ∈ Z[X ]
X 7→ α1 X 7→ α2
α1 7→ m mod N α2 7→ m mod N
Z/N Z
Jérémie Detrey — Factoring integers with CADO-NFS 11 / 22
The Number Field Sieve
I Slight problem: no unique factorization of numbers in Z[αi ] or OQ(αi )
I However, OQ(αi ) is a Dedekind domain: unique factorization of ideals
into products of prime ideals
• Prime ideals p of Z[αi ] given by integers (p, r ) such that p is prime
and fi (r ) ≡ 0 (mod p)
• pe ”divides” ha − bαi i iff. a − br ≡ 0 (mod p) and p e |Ni (a − bαi ),
where Ni (a − bαi ) = fi (a/b)b deg fi is called the norm of a − bαi
a − bX ∈ Z[X ]
X 7→ α1 X 7→ α2
α1 7→ m mod N α2 7→ m mod N
Z/N Z
Jérémie Detrey — Factoring integers with CADO-NFS 11 / 22
The Number Field Sieve
I Slight problem: no unique factorization of numbers in Z[αi ] or OQ(αi )
I However, OQ(αi ) is a Dedekind domain: unique factorization of ideals
into products of prime ideals
• Prime ideals p of Z[αi ] given by integers (p, r ) such that p is prime
and fi (r ) ≡ 0 (mod p)
• pe ”divides” ha − bαi i iff. a − br ≡ 0 (mod p) and p e |Ni (a − bαi ),
where Ni (a − bαi ) = fi (a/b)b deg fi is called the norm of a − bαi
a − bX ∈ Z[X ]
X 7→ α1 X 7→ α2
I Let’s recap!
I Let’s recap!
• Sieving domain: coprime pairs (a, b) in [−A, A]×]0, A]
I Let’s recap!
• Sieving domain: coprime pairs (a, b) in [−A, A]×]0, A]
• Factor base Bi : prime ideals p = (p, r ) of Z[αi ] with p ≤ Bi
I Let’s recap!
• Sieving domain: coprime pairs (a, b) in [−A, A]×]0, A]
• Factor base Bi : prime ideals p = (p, r ) of Z[αi ] with p ≤ Bi
I Let’s recap!
• Sieving domain: coprime pairs (a, b) in [−A, A]×]0, A]
• Factor base Bi : prime ideals p = (p, r ) of Z[αi ] with p ≤ Bi
I Let’s recap!
• Sieving domain: coprime pairs (a, b) in [−A, A]×]0, A]
• Factor base Bi : prime ideals p = (p, r ) of Z[αi ] with p ≤ Bi
I Let’s recap!
• Sieving domain: coprime pairs (a, b) in [−A, A]×]0, A]
• Factor base Bi : prime ideals p = (p, r ) of Z[αi ] with p ≤ Bi
I Let’s recap!
• Sieving domain: coprime pairs (a, b) in [−A, A]×]0, A]
• Factor base Bi : prime ideals p = (p, r ) of Z[αi ] with p ≤ Bi
Ñ Profit!
Í Filtering filter/{dup1,dup2,purge,merge,replay}
Ï Characters linalg/characters
Ê Polynomial selection
scripts/cadofactor/cadofactor.py
polyselect/polyselect2l
Python script + parameter file
Í Filtering filter/{dup1,dup2,purge,merge,replay}
Ï Characters linalg/characters
scripts/cadofactor/cadofactor.py
polyselect/polyselect2l
Python script + parameter file
Í Filtering filter/{dup1,dup2,purge,merge,replay}
Ï Characters linalg/characters
I Requirements:
• GNU/Linux (or Mac OS X + Xcode)
• GCC 4.4 or later
• GMP 5 or later
• GNU Make and CMake 2.6.3 or later
• Python 3.2 or later
• SQLite 3, including Python bindings
• GNU Wget or cURL
• GNU Gzip
• GNU Bash
I Un-tar:
$ tar xzvf cado-nfs-2.1.1.tar.gz
$ cd cado-nfs-2.1.1
I Un-tar:
$ tar xzvf cado-nfs-2.1.1.tar.gz
$ cd cado-nfs-2.1.1
I Un-tar:
$ tar xzvf cado-nfs-2.1.1.tar.gz
$ cd cado-nfs-2.1.1
I Build:
$ make
I Special-q sieving:
I Special-q sieving:
• Fix a prime ideal q = (q, ρ) of Z[α1]
I Special-q sieving:
• Fix a prime ideal q = (q, ρ) of Z[α1]
• The set of (a, b) pairs such that q divides ha − bαi i is a Euclidean
lattice of Z2
I Special-q sieving:
• Fix a prime ideal q = (q, ρ) of Z[α1]
• The set of (a, b) pairs such that q divides ha − bαi i is a Euclidean
lattice of Z2
• Compute basis (u, v) of this lattice
I Special-q sieving:
• Fix a prime ideal q = (q, ρ) of Z[α1]
• The set of (a, b) pairs such that q divides ha − bαi i is a Euclidean
lattice of Z2
• Compute basis (u, v) of this lattice
• Enumerate lattice elements as pairs (a, b) = iu + jv with
(i, j) ∈ [−I , I ]×]0, I ]
I Special-q sieving:
• Fix a prime ideal q = (q, ρ) of Z[α1]
• The set of (a, b) pairs such that q divides ha − bαi i is a Euclidean
lattice of Z2
• Compute basis (u, v) of this lattice
• Enumerate lattice elements as pairs (a, b) = iu + jv with
(i, j) ∈ [−I , I ]×]0, I ]
• One independent subtask for each special-q
→ easy parallelization
Happy factoring!