An Implementation of the Number Field Sieve
Transcript of An Implementation of the Number Field Sieve
-
8/13/2019 An Implementation of the Number Field Sieve
1/28
Centrum voor Wiskunde en Informatica
REPORTRAPPORT
An implementation of the number field sieve
R.M. Huizing
Department of Numerical Mathematics
NM-R9511 1995
-
8/13/2019 An Implementation of the Number Field Sieve
2/28
Report NM-R9511
ISSN 0169-0388
CWI
P.O. Box 94079
1090 GB Amsterdam
The Netherlands
CWI is the National Research Institute for Mathematics
and Computer Science. CWI is part of the Stichting
Mathematisch Centrum (SMC), the Dutch foundation
for promotion of mathematics and computer science
and their applications.
SMC is sponsored by the Netherlands Organization for
Scientific Research (NWO). CWI is a member of
ERCIM, the European Research Consortium for
Informatics and Mathematics.
Copyright Stichting Mathematisch Centrum
P.O. Box 94079, 1090 GB Amsterdam (NL)
Kruislaan 413, 1098 SJ Amsterdam (NL)
Telephone +31 20 592 9333
Telefax +31 20 592 4199
-
8/13/2019 An Implementation of the Number Field Sieve
3/28
A n I m p l e m e n t a t i o n o f t h e N u m b e r F i e l d S i e v e
M a r i j e H u i z i n g
C W I
P . O . B o x 9 4 0 7 9 , 1 0 9 0 G B A m s t e r d a m , T h e N e t h e r l a n d s
m a r i j e @ c w i . n l
A b s t r a c t
T h e N u m b e r F i e l d S i e v e ( N F S ) i s t h e a s y m p t o t i c a l l y f a s t e s t k n o w n f a c t o r i n g a l g o r i t h m f o r l a r g e i n t e g e r s .
T h i s a r t i c l e d e s c r i b e s a n i m p l e m e n t a t i o n o f t h e N F S , i n c l u d i n g t h e c h o i c e o f t w o q u a d r a t i c p o l y n o m i a l s , b o t h
c l a s s i c a l a n d l a t t i c e s i e v i n g , t h e b l o c k L a n c z o s m e t h o d a n d a n e w s q u a r e r o o t a l g o r i t h m . F i n a l l y s o m e d a t a o n
f a c t o r i z a t i o n s o b t a i n e d w i t h t h i s i m p l e m e n t a t i o n a r e l i s t e d , i n c l u d i n g t h e r e c o r d f a c t o r i z a t i o n o f 1 2
1 5 1
1
A M S S u b j e c t C l a s s i c a t i o n ( 1 9 9 1 ) : 1 1 Y 0 5 , 1 1 Y 4 0
K e y w o r d s & P h r a s e s : n u m b e r e l d s i e v e , f a c t o r i z a t i o n
N o t e : T h i s r e p o r t h a s b e e n s u b m i t t e d f o r p u b l i c a t i o n e l s e w h e r e .
N o t e : T h i s r e s e a r c h i s f u n d e d b y t h e N e d e r l a n d s e O r g a n i s a t i e v o o r W e t e n s c h a p p e l i j k O n d e r z o e k ( N e t h e r l a n d s
O r g a n i z a t i o n f o r S c i e n t i c R e s e a r c h , N W O ) t h r o u g h t h e S t i c h t i n g M a t h e m a t i s c h C e n t r u m ( S M C ) , u n d e r g r a n t
n u m b e r 6 1 1 - 3 0 7 - 0 2 2 .
1 . I n t r o d u c t i o n
T h e N u m b e r F i e l d S i e v e ( N F S ) | i n t r o d u c e d i n 1 9 8 8 b y J o h n P o l l a r d 1 9 ] | i s t h e a s y m p -
t o t i c a l l y f a s t e s t k n o w n a l g o r i t h m f o r f a c t o r i n g i n t e g e r s . T w o f o r m s o f t h e N F S h a v e b e e n c o n -
s i d e r e d : t h e S p e c i a l N F S ( S N F S ) , t a i l o r e d e s p e c i a l l y f o r i n t e g e r s o f t h e f o r m n = c
1
r
t
+ c
2
s
u
,
a n d t h e G e n e r a l N F S ( G N F S ) , w h i c h i s a p p l i c a b l e f o r a r b i t r a r y n u m b e r s . T h e N F S f a c t o r s
i n t e g e r s n i n h e u r i s t i c t i m e
e x p
( c + o ( 1 ) ) ( l o g n )
1 = 3
( l o g l o g n )
2 = 3
a s n ! 1 . H e r e c = (
3 2
9
)
1 = 3
1 : 5 f o r t h e S N F S a n d c = (
6 4
9
)
1 = 3
1 : 9 f o r t h e G N F S 3 ] .
T h e s e c o m p a r e w i t h t h e t i m e
e x p
( 1 + o ( 1 ) ) ( l o g n )
1 = 2
( l o g l o g n )
1 = 2
t a k e n b y t h e M u l t i p l e P o l y n o m i a l Q u a d r a t i c S i e v e ( M P Q S ) 2 1 ] , w h i c h s t i l l i s t h e b e s t g e n e r a l -
p u r p o s e f a c t o r i n g a l g o r i t h m f o r i n t e g e r s w i t h l e s s t h a n a p p r o x i m a t e l y 1 1 0 d i g i t s .
T h i s a r t i c l e d e s c r i b e s s e v e r a l e x p e r i m e n t s c a r r i e d o u t w i t h a n i m p l e m e n t a t i o n o f t h e N F S
w r i t t e n b y J . B u h l e r , R . M . H u i z i n g , P . L . M o n t g o m e r y , R . R o b s o n a n d R . R u b y . A m o n g
o t h e r s , i t h a s b e e n u s e d f o r t h e r e c o r d S N F S f a c t o r i z a t i o n o f ( 1 2
1 5 1
1 ) = 1 1 , a n u m b e r o f
1 6 2 d e c i m a l d i g i t s , a n d a G N F S f a c t o r i z a t i o n o f a 1 0 7 - d i g i t c o f a c t o r o f 6
2 2 3
+ 1 . F i r s t , a
d e s c r i p t i o n o f t h e N F S a n d a n o u t l i n e o f t h e i m p l e m e n t a t i o n w i l l b e g i v e n ; s e c o n d l y , s e v e r a l
p a r t s o f t h e i m p l e m e n t a t i o n w i l l b e d e s c r i b e d i n m o r e d e t a i l a n d n a l l y t h e r e s u l t s o f t h e
f a c t o r i z a t i o n e x p e r i m e n t s w i l l b e s t a t e d . D e t a i l e d d e s c r i p t i o n s o f t h e N F S c a n b e f o u n d i n
1 3 ] a n d 3 ] .
-
8/13/2019 An Implementation of the Number Field Sieve
4/28
-
8/13/2019 An Implementation of the Number Field Sieve
5/28
2 . D e s c r i p t i o n o f t h e N F S 3
c o l l e c t i o n
F
i
( C ) = f ( p ; ( r
1
: r
2
) ) j p p r i m e ; p < C ; ( r
1
: r
2
) 2 R
i
( p ) g : ( 2 . 2 )
H e u r i s t i c a l l y j F
i
( C ) j i s a p p r o x i m a t e l y t h e n u m b e r o f p r i m e s b e l o w C 1 0 , C h a p t e r V I I I , x 4 ] .
F
1
( B
1
) a n d F
2
( B
2
) a r e c a l l e d t h e f a c t o r b a s e s . F o r a a n d b c o p r i m e , t h e i n t e g e r F
i
( a ; b ) i s
d i v i s i b l e b y a p r i m e n u m b e r p i f a n d o n l y i f ( a m o d p : b m o d p ) 2 R
i
( p ) . T h e r e f o r e w e c a n
w r i t e f o r a r e l a t i o n ( a
j
; b
j
)
F
1
( a
j
; b
j
) =
Y
( p ; ( r
1
: r
2
) ) 2 F
1
( B
1
)
p
s
( 1 )
j p r
1
r
2
( 2 . 3 )
F
2
( a
j
; b
j
) =
Y
( p ; ( r
1
: r
2
) ) 2 F
2
( B
2
)
p
s
( 2 )
j p r
1
r
2
( 2 . 4 )
w h e r e s
( i )
j p r
1
r
2
= s
( i )
j p
i f ( a
j
m o d p : b
j
m o d p ) = ( r
1
: r
2
) a n d 0 o t h e r w i s e .
L e t v ( a
j
; b
j
) b e a v e c t o r o f l e n g t h 1 +
j F
1
( B
1
)
j+
j F
2
( B
2
)
jc o n t a i n i n g 1 a n d a l l s
( 1 )
j p r
1
r
2
m o d 2
a n d s
( 2 )
j p r
1
r
2
m o d 2 , i n a n o r d e r w h i c h i s x e d f o r a l l r e l a t i o n s ( a
j
; b
j
) . A n o n - e m p t y s u b s e t S
o f r e l a t i o n s s u c h t h a t
P
S
v ( a ; b ) 0 m o d 2 i s a l m o s t s u c i e n t t h a t
Q
S
( a b
i
) b e a s q u a r e
i n Q
n
i
] f o r i = 1 ; 2 3 , x 1 2 . 7 ] . I t i s n o t t o t a l l y s u c i e n t a s c a n b e s e e n f r o m t h e f o l l o w i n g
e x a m p l e : I n t h e e l d Q (
p
3 ) g e n e r a t e d b y a r o o t o f t h e p o l y n o m i a l f ( x ) = x
2
3 , t h e e l e m e n t
2 +
p
3 h a s n o r m F ( 2 ; 1 ) = 1 . S o a l l e x p o n e n t s s
( 1 )
j p r
1
r
2
a n d s
( 2 )
j p r
1
r
2
w i l l b e z e r o . F u r t h e r m o r e
v ( 2 ; 1 ) + v ( 1 ; 0 ) 0 m o d 2 . B u t i t s s q u a r e r o o t i s (
p
6 +
p
2 ) = 2 , w h i c h i s n o t a n e l e m e n t o f
Q (
p
3 ) .
T h e s m a l l g a p b e t w e e n b e i n g a l m o s t a s q u a r e a n d b e i n g p r a c t i c a l l y c e r t a i n a s q u a r e i s
o v e r c o m e b y u s i n g q u a d r a t i c c h a r a c t e r s , f o l l o w i n g a n i d e a o f A d l e m a n 1 ] . L e t
Q
S
( a b
i
)
b e a s q u a r e i n Q
n
i
] w i t h S f ( a ; b ) 2 Z
2
j a a n d b c o p r i m e g a n d l e t q b e a n o d d p r i m e
n u m b e r n o t d i v i d i n g c
1 ; d
1
c
2 ; d
2
. I f ( s
1
: s
2
) 2 R
i
( q ) s u c h t h a t f
0
i
( s
1
s
1
2
m o d q ) 6 0 m o d q a n d
( a m o d q : b m o d q ) 6= ( s
1
: s
2
) f o r a l l ( a ; b ) 2 S , t h e n
Y
( a ; b ) 2 S
a b ( s
1
s
1
2
m o d q )
q
!
= 1 ( 2 . 5 )
w h e r e
v
w
d e n o t e s t h e L e g e n d r e s y m b o l 3 , x 8 , x 1 2 . 7 ] . W e u s e t h i s b y t a k i n g f o r e a c h
p o l y n o m i a l s e v e r a l p r i m e s q l a r g e r t h a n B
i
a n d n o t d i v i d i n g c
i ; d
i
, t o g e t h e r w i t h a n e l -
e m e n t ( s
1
: s
2
) 2 R
i
( q ) s u c h t h a t f
0
i
( s
1
s
1
2
m o d q ) 6 0 m o d q . S i n c e q > B
i
w e h a v e
( a m o d q : b m o d q ) 6= ( s
1
: s
2
) f o r a l l r e l a t i o n s ( a ; b ) . A p p e n d t o t h e v e c t o r v ( a ; b ) f o r a l l
p a i r s ( q ; ( s
1
: s
2
) ) a z e r o i f
a b ( s
1
s
1
2
m o d q )
q
= 1 a n d a o n e o t h e r w i s e . N o w a n o n - e m p t y
s u b s e t S o f a l l r e l a t i o n s s u c h t h a t
P
S
v ( a ; b ) 0 m o d 2 g u a r a n t e e s t h a t ( 2 . 5 ) h o l d s f o r a l l
c h o s e n p r i m e s q t o g e t h e r w i t h t h e i r e l e m e n t s ( s
1
: s
2
) 2 R
i
( q ) . T a k i n g e n o u g h q u a d r a t i c c h a r -
a c t e r s | w e t o o k 3 2 p e r p o l y n o m i a l | m a k e s i t p r a c t i c a l l y c e r t a i n t h a t b o t h
Q
S
( a b
i
) a r e
s q u a r e s i n Q
n
i
] . A l s o t h e a b o v e c o u n t e r e x a m p l e c o u l d h a v e b e e n c a u g h t , u s i n g q u a d r a t i c
c h a r a c t e r s : t a k e q = 1 1 a n d ( s
1
: s
2
) = ( 5 ; 1 ) 2 R ( 1 1 ) . T h e L e g e n d r e s y m b o l b e c o m e s
2 + 5
1 1
,
w h i c h i s 1 .
I f Q i s t h e t o t a l n u m b e r o f q u a d r a t i c c h a r a c t e r s u s e d , t h e n a n o n - e m p t y s u b s e t S s u c h t h a t
P
S
v ( a ; b ) 0 m o d 2 c a n a l w a y s b e f o u n d i f t h e n u m b e r o f r e l a t i o n s e x c e e d s 1 + j F
1
( B
1
) j +
j F
2
( B
2
) j + Q .
-
8/13/2019 An Implementation of the Number Field Sieve
6/28
3 . O u t l i n e o f t h e i m p l e m e n t a t i o n 4
3 . O u t l i n e o f t h e i m p l e m e n t a t i o n
T h e i m p l e m e n t a t i o n c a n b e d i v i d e d i n t o v e s t a g e s . I n t h e r s t s t a g e w e s e l e c t b o t h p o l y n o -
m i a l s f
1
( x ) ; f
2
( x ) 2 Z x ] a n d t h e i n t e g e r m s u c h t h a t m i s a c o m m o n r o o t o f f
1
( x ) a n d f
2
( x )
m o d u l o n . F u r t h e r m o r e t h e s i e v i n g r e g i o n | t h i s i s t h e c o l l e c t i o n o f ( a ; b ) - p a i r s f o r w h i c h
b o t h F
i
( a ; b ) a r e c h e c k e d f o r s m o o t h n e s s | a n d , f o r e a c h p o l y n o m i a l , a f a c t o r b a s e b o u n d B
i
h a v e t o b e c h o s e n .
T h e s e c o n d s t a g e i s t h e s i e v i n g i n w h i c h t h e r e l a t i o n s a r e f o u n d . T h i s i s t h e m o s t t i m e -
c o n s u m i n g p a r t . I n t h i s i m p l e m e n t a t i o n a r e l a t i o n i s a p a i r ( a ; b ) f r o m t h e s i e v i n g r e g i o n
s u c h t h a t b o t h F
i
( a ; b ) f a c t o r c o m p l e t e l y o v e r t h e p r i m e s b e l o w B
i
, e x c e p t f o r a t m o s t t w o
l a r g e p r i m e n u m b e r s , w h i c h s h o u l d b e b e t w e e n B
i
a n d a l a r g e p r i m e b o u n d L
i
. T h e p r o d u c t s
i n ( 2 . 3 ) a n d ( 2 . 4 ) a r e t a k e n o v e r F ( L
1
) a n d F ( L
2
) , r e s p e c t i v e l y a n d t h e v e c t o r s v ( a ; b ) h a v e
t o b e a d a p t e d a c c o r d i n g l y .
T h i s i s f o l l o w e d b y a l t e r i n g s t a g e w i t h t h e p u r p o s e o f r e d u c i n g t h e a m o u n t o f d a t a . H e r e
s o m e r e l a t i o n s a r e e l i m i n a t e d a n d o t h e r s a r e g r o u p e d i n t o r e l a t i o n - s e t s .
I n t h e f o u r t h s t a g e , w e c o n s t r u c t a m a t r i x b y t a k i n g t h e v e c t o r s v ( a ; b ) a n d t h e v e c t o r s
P
( a ; b ) 2 V
v ( a ; b ) f o r a l l r e m a i n i n g r e l a t i o n s a n d r e l a t i o n - s e t s V a s c o l u m n s . F i n d i n g a n o n -
e m p t y s e t S s u c h t h a t
P
S
v ( a ; b ) 0 m o d 2 i s t h e s a m e a s c a l c u l a t i n g a n o n - t r i v i a l v e c t o r
f r o m t h e n u l l s p a c e o f t h i s m a t r i x o v e r F
2
. F o r h u g e s p a r s e m a t r i c e s t h e b e s t k n o w n m e t h o d s
a r e i t e r a t i v e o n e s , s u c h a s t h e b l o c k L a n c z o s a l g o r i t h m 1 7 ] . T h e o u t p u t o f t h i s s t a g e i s a
s u b s e t S o f t h e r e l a t i o n s s u c h t h a t b o t h
Q
S
( a b
1
) a n d
Q
S
( a b
2
) a r e s q u a r e s
2
a n d
2
i n Q
n
1
] a n d Q
n
2
] , r e s p e c t i v e l y .
T h e n a l s t a g e c o n s i s t s o f e x t r a c t i n g t h e s q u a r e r o o t o f b o t h s q u a r e s m e n t i o n e d a b o v e .
T h i s i s d o n e b y a n e w a l g o r i t h m , d e v e l o p e d b y M o n t g o m e r y 1 6 ] . I n a n i t e r a t i v e p r o c e s s t h e
s q u a r e r o o t i s a p p r o x i m a t e d , t h e r e b y l e a v i n g a ` s m a l l e r ' r e m a i n d e r o f w h i c h w e h a v e t o e x t r a c t
t h e s q u a r e r o o t . I f t h e r e m a i n d e r i s s m a l l e n o u g h w e u s e a c o n v e n t i o n a l m e t h o d . F i n a l l y w e
a p p l y t h e h o m o m o r p h i s m s
1
a n d
2
t o t h e s q u a r e r o o t s a n d , r e s p e c t i v e l y a n d c a l c u l a t e
t h e g c d o f n a n d
1
( )
2
( ) , w h i c h w i l l s p l i t n i n t o t w o n o n - t r i v i a l f a c t o r s i n a t l e a s t h a l f
o f t h e c a s e s .
4 . F r e e r e l a t i o n s
D e n o t e b y g t h e o r d e r o f t h e G a l o i s g r o u p o f f
1
( x ) f
2
( x ) . F o r a p p r o x i m a t e l y 1 = g o f t h e
p r i m e s q
-
8/13/2019 An Implementation of the Number Field Sieve
7/28
5 . C h o i c e o f t h e p o l y n o m i a l s 5
i s a s q u a r e i n Z . L i k e w e p a r t i t i o n e d t h e p r i m e s p d i v i d i n g
Q
( a ; b ) 2 S
F
i
( a ; b ) a c c o r d i n g t o t h e
r o o t s ( a m o d p : b m o d p ) 2 R
i
( p ) , w e c o n s i d e r p
d
i
a s t h e p r o d u c t o f o n e f a c t o r p f o r e v e r y r o o t
( r
1
: r
2
) 2 R
i
( p ) . W e a s s o c i a t e w i t h e v e r y f r e e p r i m e p
-
8/13/2019 An Implementation of the Number Field Sieve
8/28
5 . C h o i c e o f t h e p o l y n o m i a l s 6
-1000000
-500000
0
500000
1000000
a
0
100000
200000
300000
b
0
5000
10000
15000
20000
#
F i g u r e 1 : N u m b e r o f r e l a t i o n s f o u n d p e r 6 0 0 0 0 a - v a l u e s a n d 8 6 2 5 b - v a l u e s f o r t h e f a c t o r i z a t i o n
o f a C 1 1 9 f r o m 3
3 1 9
1 . O n e p o l y n o m i a l i s f
1
( x ) = x
5
+ x
4
4 x
3
3 x
2
+ 3 x + 1 w i t h 5 r e a l
r o o t s . T h e v e r i d g e s i n d i c a t e a h i g h e r y i e l d f o r p a i r s ( a ; b ) w i t h a = b n e a r a r o o t .
p r o b a b i l i t y t h a t F
i
( a ; b ) i s s m a l l a f t e r d i v i d i n g i t b y t h e s e s m a l l p r i m e n u m b e r s , m a k i n g i t
m o r e l i k e l y t o b e s m o o t h o v e r t h e p r i m e s b e l o w B
i
. F i n a l l y i t i s b e t t e r t o c h o o s e p o l y n o m i a l s
f o r w h i c h t h e o r d e r o f t h e G a l o i s g r o u p o f f
1
( x ) f
2
( x ) i s s m a l l , s i n c e w e s a w i n t h e p r e v i o u s
S e c t i o n t h a t t h e y p r o v i d e m o r e f r e e r e l a t i o n s . W i t h t h e s e c r i t e r i a i n m i n d w e s e l e c t t h e p a i r
o f p o l y n o m i a l s w h i c h i s e x p e c t e d t o b e t h e b e s t .
W e e x p e r i m e n t e d w i t h a c h o i c e o f t w o q u a d r a t i c p o l y n o m i a l s s e l e c t e d a c c o r d i n g t o i d e a s o f
M o n t g o m e r y 4 ] . H e o b s e r v e d t h a t f
1
( x ) = c
1 ; 2
x
2
+ c
1 ; 1
x + c
1 ; 0
a n d f
2
( x ) = c
2 ; 2
x
2
+ c
2 ; 1
x + c
2 ; 0
2
Z x ] h a v e a c o m m o n r o o t m m o d u l o n i f a n d o n l y i f t h e v e c t o r s a = ( c
1 ; 0
; c
1 ; 1
; c
1 ; 2
)
T
a n d b
= ( c
2 ; 0
; c
2 ; 1
; c
2 ; 2
)
T
a r e o r t h o g o n a l t o ( 1 ; m ; m
2
)
T
o v e r Z = n Z u s i n g t h e s t a n d a r d i n n e r p r o d u c t .
S u p p o s e f
1
( x ) a n d f
2
( x ) a r e i r r e d u c i b l e o v e r Z , c o n t ( f
i
) = 1 ( i = 1 ; 2 ) a n d t h a t f
1
6= f
2
. I n
p r a c t i c e t h e c o e c i e n t s o f a a n d b a r e s m a l l e r t h a n
O(
p
n ) . T h e r e f o r e t h e s p a c e o r t h o g o n a l
t o a a n d b h a s r a n k 1 ( b o t h o v e r Z a n d o v e r Z = n Z ) . I f c = a
b ( c r o s s p r o d u c t ) , t h e n c
m u s t b e a m u l t i p l e o f ( 1 ; m ; m
2
)
T
o v e r Z = n Z . T h e f a c t t h a t f
1
( x ) a n d f
2
( x ) a r e n o t m u l t i p l e s
o f e a c h o t h e r e n s u r e s t h a t c i s n o t t h e z e r o v e c t o r . I f c = ( c
0
; c
1
; c
2
)
T
, t h e n c
0
; c
1
; c
2
i s a
g e o m e t r i c p r o g r e s s i o n i n Z = n Z . I t i s n o t a g e o m e t r i c p r o g r e s s i o n o v e r Z , s i n c e t h e n f
1
( x ) a n d
f
2
( x ) w o u l d h a v e a c o m m o n f a c t o r ( x m ) o v e r Z .
M o n t g o m e r y ' s a l g o r i t h m f o r n d i n g f
1
( x ) a n d f
2
( x ) r e v e r s e s t h i s c o n s t r u c t i o n a n d s t a r t s
w i t h a v e c t o r c = ( c
0
; c
1
; c
2
)
T
2 Z
3
, w h e r e c
0
; c
1
; c
2
i s a g e o m e t r i c p r o g r e s s i o n w i t h r a t i o m
o v e r Z = n Z , b u t n o t o v e r Z . T h e v e c t o r c c a n b e c o n s t r u c t e d a s f o l l o w s : f o r p p r i m e s u c h
t h a t p
-
8/13/2019 An Implementation of the Number Field Sieve
9/28
5 . C h o i c e o f t h e p o l y n o m i a l s 7
a
0
=
0
B
@
c
1
p
0
1
C
A
a n d b
0
=
0
B
@
( c
1
( c
2
s m o d p ) c
2
) = p
( c
2
s m o d p )
1
1
C
A
a r e b o t h o r t h o g o n a l t o c . F r o m a
0
b
0
= c a n d g c d ( c
0
; c
1
; c
2
) = 1 w e d e d u c e t h a t a
0
a n d
b
0
s p a n t h e s u b l a t t i c e o f Z
3
o r t h o g o n a l t o c . D e n o t e b y ( a ; b ) t h e i n n e r p r o d u c t o f a a n d b
a n d r e m e m b e r t h a t
( a ; b )
( a ; a )
a i s t h e p r o j e c t i o n o f b o n a . B y r e d u c i n g t h e b a s i s f a
0
; b
0
g , o n e
c a n n d ` s m a l l ' v e c t o r s a a n d b w i t h f a ; b g a b a s i s o f t h e s u b l a t t i c e o f Z
3
o r t h o g o n a l t o c ,
s u c h t h a t
( a ; b )
( a ; a )
1
2
a n d
( a ; b )
( b ; b )
1
2
. T h e a n g l e b e t w e e n t h e s e v e c t o r s w i l l b e b e t w e e n 6 0
a n d 1 2 0 d e g r e e s . S i n c e t h e s u r f a c e o f t h e p a r a l l e l o g r a m s p a n n e d b y a a n d b i s b o t h e q u a l t o
k a b k a n d k a k k b k s i n , w e h a v e
k a k k b k =
k c k
s i n
2 k c k
p
3
= O ( k c k ) = O ( n
1 = 2
) : ( 5 . 7 )
I n p r a c t i c e b o t h k a k a n d k b k a r e O ( n
1 = 4
) . F o r d i e r e n t v a l u e s o f p w e w i l l g e t a d i e r e n t
p a i r o f p o l y n o m i a l s . T h e p r o g r a m n d q u a d t r i e s t o n d t w o p o l y n o m i a l s e a c h h a v i n g t w o
r e a l r o o t s , m a n y r o o t s m o d u l o s m a l l p r i m e s a n d w i t h t h e i n t e g r a l o f
P
i = 1 ; 2
l o g j F
i
( x ; y ) j ,
w h e r e ( x ; y ) r u n s t h r o u g h t h e s i e v i n g r e g i o n f o r ( a ; b ) , s m a l l .
W h e n u s i n g l a t t i c e s i e v i n g ( e x p l a i n e d i n S e c t i o n 6 ) w e l i k e t o u s e a l a r g e r a n g e o f a - v a l u e s ,
s a y j a j < M a n d o n l y b = 1 . F o r s t i m u l a t i n g F
i
( a ; 1 ) = c
i ; 2
a
2
+ c
i ; 1
a + c
i ; 0
t o b e s m o o t h
o v e r t h e p r i m e n u m b e r s b e l o w B
i
, w e w o u l d p r e f e r c
i ; 2
= O ( n
1 = 4
= M ) , c
i ; 1
= O ( n
1 = 4
) a n d
c
i ; 0
= O ( n
1 = 4
M ) r a t h e r t h a n a l l o f t h e m b e i n g O ( n
1 = 4
) . W e a c h i e v e t h i s b y r s t c h o o s i n g
c
0
= p = O (
p
n = M ) , w h e n c e c
1
= O (
p
n ) a n d c
2
= O (
p
n M ) . T h e r e s u l t i n g c o e c i e n t s o f a
0
= ( a
0
0
; a
0
1
; a
0
2
) a n d b
0
= ( b
0
0
; b
0
1
; b
0
2
) h a v e a p p r o x i m a t e l y t h e r i g h t r a t i o . T o k e e p t h i s r a t i o w h i l e
r e d u c i n g t h e b a s i s , w e r e d u c e t h e v e c t o r s a
0 0
= ( a
0
0
; a
0
1
M ; a
0
2
M
2
) a n d b
0 0
= ( b
0
0
; b
0
1
M ; b
0
2
M
2
)
i n s t e a d . N o t e t h a t a
0 0
b
0 0
= M c
0 0
w i t h c
0 0
= ( c
0
M
2
; c
1
M ; c
2
) , w h i c h s t i l l i s a g e o m e t r i c
p r o g r e s s i o n w i t h r a t i o c
1
= p M o v e r Z = n Z , n o t o v e r Z . U s i n g ( 5 . 7 ) w i t h c = M c
0 0
w e n d t h a t
t h e r e s u l t i n g v e c t o r s a = ( a
0
; a
1
M ; a
2
M
2
) a n d b = ( b
0
; b
1
M ; b
2
M
2
) w i l l b e b o t h
O( n
1 = 4
M ) .
U s i n g f
1
( x ) = a
2
x
2
+ a
1
x + a
0
a n d f
2
( x ) = b
2
x
2
+ b
1
x + b
0
r e s u l t s i n t h e d e s i r e d o r d e r s o f t h e
c o e c i e n t s o f f
1
a n d f
2
.
W e a l s o h a v e t o c h o o s e t h e f a c t o r b a s e b o u n d s B
i
, t h e l a r g e p r i m e b o u n d s L
i
a n d t h e s i e v i n g
r e g i o n . I n t h e e x p e r i m e n t s d e s c r i b e d i n t h e l a s t S e c t i o n | w h e r e w e f a c t o r e d n u m b e r s i n
t h e 9 8 { 1 6 2 d i g i t s r a n g e w i t h t h e S N F S a n d n u m b e r s i n t h e 8 7 { 1 0 7 d i g i t s r a n g e w i t h t h e
G N F S | w e u s e d f a c t o r b a s e b o u n d s b e t w e e n 5 1 0
5
a n d 2 : 9 1 0
6
a n d l a r g e p r i m e b o u n d s
b e t w e e n 1 2 1 0
6
a n d 4 1 0
7
. T h e s i e v i n g r e g i o n w a s a r e c t a n g l e f o r w h i c h w e t o o k a i n a
s u b i n t e r v a l o f 2 1 0
6
; 2 1 0
6
] a n d b b e t w e e n 1 a n d s o m e u p p e r b o u n d , i n o u r e x p e r i m e n t s
b e t w e e n 1 6 1 0
3
a n d 4 8 1 0
4
. F i r s t w e c h o s e t h e f a c t o r b a s e b o u n d s a n d g e n e r a t e d t h e
c o r r e s p o n d i n g f a c t o r b a s e s F
i
( B
i
) ( a s d e s c r i b e d i n t h e n e x t S e c t i o n ) . T h e n w e c h o s e t h e l a r g e
p r i m e b o u n d s L
i
a n d x e d a r a n g e o f a - v a l u e s . F o r a l l t h e s e a - v a l u e s a n d a f e w b - v a l u e s ,
p r e f e r a b l y e q u i d i s t r i b u t e d o v e r t h e e x p e c t e d r a n g e o f t h e b - v a l u e s , w e c h e c k e d w h e t h e r t h e
( a ; b ) - p a i r i s a r e l a t i o n , i n a w a y w e w i l l d e s c r i b e i n t h e n e x t S e c t i o n . A l l o w i n g F
i
( a ; b ) t o
c o n t a i n t w o l a r g e p r i m e s b e t w e e n B
i
a n d L
i
, i n s t e a d o f d e m a n d i n g i t t o b e s m o o t h o v e r t h e
p r i m e s b e l o w B
i
, w e e n l a r g e t h e p r o b a b i l i t y t h a t ( a ; b ) i s a r e l a t i o n . O n t h e o t h e r h a n d ,
F
i
( a ; b ) i s n o w f a c t o r e d o v e r F
i
( L
i
) i n s t e a d o f F
i
( B
i
) , w h i c h e n l a r g e s t h e n u m b e r o f r e l a t i o n s
-
8/13/2019 An Implementation of the Number Field Sieve
10/28
6 . T h e s i e v i n g 8
n e e d e d t o o . I n p r a c t i c e t h i s a d j u s t m e n t h a s s h o w n t o b e u s e f u l . I n o u r e x p e r i m e n t s w e n e e d e d
a p p r o x i m a t e l y 0 : 8 f ( L
1
) + ( L
2
) ( m i n ( L
1
; L
2
) ) = g g r e l a t i o n s .
F r o m t h e n u m b e r o f r e l a t i o n s w e g o t f o r t h e s e f e w b - v a l u e s w e c o u l d e s t i m a t e t h e r a n g e o f
b - v a l u e s n e e d e d a n d f r o m t h e t i m e t h e e x p e r i m e n t t o o k w e c o u l d e s t i m a t e t h e t i m e n e e d e d
f o r t h e w h o l e s i e v i n g s t e p . I n t h i s w a y w e s e l e c t e d a g o o d c o m b i n a t i o n o f p a i r o f p o l y n o m i a l s ,
f a c t o r b a s e b o u n d s , l a r g e p r i m e b o u n d s a n d s i e v i n g r e g i o n .
6 . T h e s i e v i n g
T h e s i e v i n g i s t h e p a r t o f t h e a l g o r i t h m d u r i n g w h i c h w e c o l l e c t t h e r e l a t i o n s . B e f o r e w e
s t a r t t h e s i e v i n g w e h a v e t o g e n e r a t e t h e f a c t o r b a s e s F
i
( B
i
) a c c o r d i n g t o ( 2 . 2 ) . I f w e i d e n t i f y
P
1
( F
p
) w i t h F
p
f 1 g b y i d e n t i f y i n g ( r
1
: r
2
) w i t h r
1
= r
2
, t h e n R
i
( p ) ( d e n e d i n ( 2 . 1 ) ) c o n s i s t s
o f t h o s e r = r
1
= r
2
2 F
p
f o r w h i c h f
i
( r ) 0 m o d p , t o g e t h e r w i t h 1 i f c
i ; d
i
0 m o d p . T h e
p r o g r a m r o o t n d e r n d s f o r b o t h p o l y n o m i a l s f
i
( x ) a n d f o r a l l p r i m e s p b e l o w B
i
a l l r o o t s
m o d u l o p . R e p e a t e d r o o t s a p p e a r o n l y o n c e i n t h e l i s t . W h e n t h e p r i m e p d i v i d e s t h e l e a d i n g
c o e c i e n t c
i ; d
i
r o o t n d e r i n c l u d e s t h e p r o j e c t i v e r o o t ( 1 ; 0 ) , w h i c h i t r e p r e s e n t s b y p . W e
r e c a l l t h a t f o r a a n d b c o p r i m e , p j F
i
( a ; b ) i f a n d o n l y i f ( a m o d p : b m o d p ) 2 R
i
( p ) . I n t e r m s
o f t h e r o o t s o f f
i
( x ) t h i s m e a n s t h a t f o r a a n d b c o p r i m e , p j F
i
( a ; b ) i f a n d o n l y i f ( a b r m o d p
a n d f
i
( r ) 0 m o d p ) o r ( p j c
i ; d
i
a n d p j b ) .
T w o w a y s o f s i e v i n g h a v e b e e n i m p l e m e n t e d : t h e ` c l a s s i c a l ' s i e v e , d e s c r i b e d i n 1 3 , x 4 ] a n d
3 , x 1 2 ] a n d t h e l a t t i c e s i e v e , d e s c r i b e d i n 2 0 ] .
I n t h e c l a s s i c a l w a y o f s i e v i n g w e r s t c h o o s e t h e a - i n t e r v a l a n d t h e b - i n t e r v a l . W e s t a r t
s i e v i n g w i t h b = 1 a n d w i l l a u g m e n t b u n t i l w e r e a c h i t s u p p e r b o u n d . T h e p r o g r a m g n f s
e s t i m a t e s t h e m a x i m u m v a l u e o f F
i
( a ; b ) o v e r a l l v a l u e s o f a a n d b f o r b o t h p o l y n o m i a l s .
T h e p o l y n o m i a l f o r w h i c h t h i s e s t i m a t e i s l a r g e r i s s i e v e d r s t . P r o b a b l y f e w e r p a i r s ( a ; b )
w i l l h a v e a s m o o t h v a l u e o f F
i
( a ; b ) f o r t h i s p o l y n o m i a l , s o f e w e r p a i r s h a v e t o b e s t o r e d .
F u r t h e r m o r e t h i s l a r g e s t v a l u e i s u s e d t o d e c i d e u p o n t h e b a s e o f t h e l o g a r i t h m , w h i c h w e
c h o o s e i n s u c h a w a y t h a t t h e l o g o f t h e m a x i m u m t s i n o n e b y t e . S u p p o s e w e s t a r t s i e v i n g
w i t h p o l y n o m i a l f
j
.
T o s i e v e f o r t h e r s t p o l y n o m i a l f
j
w e x b a n d i n i t i a l i z e a n a r r a y w h i c h c o n t a i n s o n e
b y t e p e r a - v a l u e t o z e r o . F o r e v e r y p r i m e p < B
j
a n d e v e r y r w i t h f
j
( r ) 0 m o d p w e
a d d l o g p ] ( w h e r e : ] i s t h e n e a r e s t i n t e g e r f u n c t i o n ) t o a l l a r r a y e l e m e n t s c o r r e s p o n d i n g
w i t h a b r m o d p . F o r e v e r y p r i m e p < B
j
w i t h p j c
j ; d
j
a n d p j b w e a d d l o g p ] t o e v e r y
a r r a y e l e m e n t . T h e n w e s p l i t t h e a - i n t e r v a l r e c u r s i v e l y i n s u b i n t e r v a l s u n t i l t h e v a l u e o f
c
j
( a ; b ) = F
j
( a ; b ) = L
2
j
d o e s n o t v a r y m o r e t h a n a p r e s c r i b e d a m o u n t o n a s u b i n t e r v a l . I f
t h e v a l u e o f a n a r r a y e l e m e n t i s c l o s e e n o u g h t o l o g c
j
( a ; b ) , t h e n F
j
( a ; b ) i s p o t e n t i a l l y
s m o o t h a n d w e s t o r e t h e v a l u e o f a . N o w t h e s a m e s i e v i n g p r o c e s s t a k e s p l a c e f o r t h e o t h e r
p o l y n o m i a l f
3 j
. I f f o r a p a i r ( a ; b ) b o t h F
1
( a ; b ) a n d F
2
( a ; b ) a r e p o t e n t i a l l y s m o o t h , w e u s e
t r i a l d i v i s i o n t o e x t r a c t a l l f a c t o r s b e l o w B
i
f r o m F
i
( a ; b ) ( i = 1 ; 2 ) . T h i s i s n e c e s s a r y , s i n c e
d u r i n g t h e s i e v i n g w e u s e r o u n d e d l o g a r i t h m s a n d o t h e r t e c h n i q u e s , w h i c h n o t o n l y m a k e t h e
s i e v i n g f a s t e r , b u t a l s o m a k e t h e n a l v a l u e i n t h e a r r a y e l e m e n t s l e s s a c c u r a t e . I f a f t e r t h e
t r i a l d i v i s i o n t h e r e r e m a i n s a c o m p o s i t e p a r t s m a l l e r t h a n L
2
i
, w e t r y t o f a c t o r i t r s t u s i n g
S Q U F O F a n d i f t h a t f a i l s u s i n g P o l l a r d R h o 2 2 , p p . 1 9 1 { 1 9 8 , p p . 1 7 4 { 1 8 3 ] . A p a i r ( a ; b )
f o r w h i c h b o t h F
i
( a ; b ) f a c t o r o v e r t h e p r i m e s b e l o w B
i
e x c e p t f o r a t m o s t t w o l a r g e p r i m e s
b e t w e e n B
i
a n d L
i
, i s a r e l a t i o n . I t i s s t o r e d t o g e t h e r w i t h t h e p r i m e s d i v i d i n g F
1
( a ; b ) a n d
F
2
( a ; b ) w h i c h e x c e e d s o m e u s e r - d e t e r m i n e d p r i n t i n g b o u n d W
i
( i = 1 ; 2 ) . W i t h t h e s e b o u n d s
-
8/13/2019 An Implementation of the Number Field Sieve
11/28
6 . T h e s i e v i n g 9
W
i
o n e c a n m o n i t o r t h e a m o u n t o f o u t p u t o f t h e g n f s p r o g r a m . T h e y s h o u l d b e c h o s e n i n
s u c h a w a y t h a t i t t s i n t h e a v a i l a b l e d i s k s p a c e .
U s i n g t h e l a t t i c e s i e v e , w e o n l y s i e v e o v e r p a i r s ( a ; b ) o f w h i c h w e k n o w t h a t o n e F
i
( a ; b ) ,
s a y F
j
( a ; b ) , i s d i v i s i b l e b y a s p e c i a l l a r g e p r i m e b e t w e e n L
( l )
a n d L
( u )
, w h i c h a r e t h e u s e r -
c h o s e n l o w e r a n d u p p e r b o u n d f o r t h e l a r g e p r i m e s , r e s p e c t i v e l y . T h e a d v a n t a g e i s t h a t t h e
r e m a i n i n g p a r t o f F
j
( a ; b ) i s m o r e l i k e l y t o b e s m o o t h . O n t h e o t h e r h a n d w e w i l l m i s s t h e
r e l a t i o n s f o r w h i c h F
j
( a ; b ) i s s m o o t h o v e r t h e p r i m e s b e l o w L
( l )
. F o r t h e i m p l e m e n t a t i o n o f
t h e l a t t i c e s i e v e w e u s e a n e x t r a f e a t u r e i m p l e m e n t e d i n t h e c l a s s i c a l w a y o f s i e v i n g . T h e r e w e
h a v e a p o s s i b i l i t y o f s i e v i n g o v e r a s u b l a t t i c e o f t h e ( a ; b ) - p a i r s . W e c a n c h o o s e a n i n t e g r a l ,
n o n - s i n g u l a r m a t r i x M a n d s i e v e o v e r p a i r s ( a ; b ) o f t h e f o r m :
a
b
!
= M
x
y
!
;
w h i l e t h e p r o g r a m s i e v e s o v e r x a n d y . T h i s i s d o n e b y s u b s t i t u t i n g t h e e x p r e s s i o n s o f a a n d b
i n t e r m s o f x a n d y i n b o t h F
i
( a ; b ) r e s u l t i n g i n n e w p o l y n o m i a l s G
i
( x ; y ) , w h i c h a r e n o w t h e
p o l y n o m i a l s t h e v a l u e s o f w h i c h s h o u l d b e s m o o t h . O f c o u r s e t h e r o o t s o f t h e p o l y n o m i a l s F
i
h a v e t o b e a d a p t e d t o t h e r o o t s o f t h e p o l y n o m i a l s G
i
. W h e n a p a i r ( x ; y ) i s a r e l a t i o n , t h e
c o r r e s p o n d i n g p a i r ( a ; b ) , t o g e t h e r w i t h t h e p r i m e s d i v i d i n g G
i
( x ; y ) a n d e x c e e d i n g W
i
, a r e
s t o r e d .
T h e l a t t i c e s i e v e s i e v e s f o r e v e r y p r i m e L
( l )
q L
( u )
, f o r a x e d v a l u e o f b o v e r a l l r o o t s
( r
1
: r
2
) 2 f R
1
( q ) R
2
( q ) g w i t h r
2
6= 0 . W h e n s i e v i n g o v e r a r o o t ( r
1
: r
2
) o f R
j
( q ) w e s i e v e
o n l y o v e r t h e a - v a l u e s w i t h a b r
1
r
1
2
m o d q , t h u s g u a r a n t e e i n g t h a t F
j
( a ; b ) i s d i v i s i b l e
b y q . T h i s i s t h e s a m e a s u s i n g a m a t r i x
M =
q r
1
r
1
2
m o d q
0 1
!
w i t h y x e d t o b a n d x i n a n i n t e r v a l s u c h t h a t q x + b ( r
1
r
1
2
m o d q ) j u s t t s i n t h e a - i n t e r v a l .
G
j
( x ; 1 ) = q s h o u l d b e s m o o t h o v e r t h e p r i m e s b e l o w B
j
, e x c e p t f o r o n e o t h e r l a r g e p r i m e
b e t w e e n B
j
a n d q . T h e o t h e r G
3 j
( x ; 1 ) s h o u l d b e s m o o t h o v e r t h e p r i m e s b e l o w B
3 j
,
e x c e p t f o r t w o l a r g e p r i m e s b e t w e e n B
3 j
a n d q . N o t a l l o w i n g p r i m e s e q u a l t o o r b i g g e r
t h a n q t o d i v i d e G
3 j
( x ; 1 ) p r e v e n t s g e t t i n g d u p l i c a t e r e l a t i o n s . A f t e r w e h a v e s i e v e d o v e r a l l
r o o t s i n R
1
( q ) a n d R
2
( q ) w e t a k e t h e n e x t v a l u e o f b a n d a f t e r w e h a v e s i e v e d o v e r a l l v a l u e s
o f b w e t a k e t h e n e x t p r i m e i n t h e i n t e r v a l L
( u )
; L
( l )
] . W e i m p l e m e n t e d l a t t i c e s i e v i n g o n l y
f o r t h e c a s e o f t w o q u a d r a t i c p o l y n o m i a l s .
S i n c e t h e s i e v i n g i s t h e m o s t t i m e - c o n s u m i n g s t e p o f t h e a l g o r i t h m , t h e w a y o f i m p l e m e n t i n g
i t i s c r i t i c a l . I t i s a l o t o f w o r k t o s i e v e o v e r a s m a l l p r i m e p a n d j u s t a s m a l l a m o u n t o f l o g p
i s a d d e d t o t h e a r r a y e l e m e n t s . T h e r e f o r e w e s i e v e o n l y o v e r t h e p r i m e s a n d p r i m e p o w e r s
l a r g e r t h a n 3 0 . F u r t h e r m o r e w e s p l i t t h e a - i n t e r v a l i n t o s u b i n t e r v a l s w h i c h t i n t h e s e c o n d a r y
c a c h e o f t h e c o m p u t e r , m a k i n g t h e s i e v i n g f a s t e r . F o r a g r o u p o f s p e c i a l a n d s m a l l p r i m e s ,
w h i c h c o n s i s t s o f t h e p r i m e s d i v i d i n g t h e l e a d i n g c o e c i e n t o f o n e o f t h e p o l y n o m i a l s a n d t h e
p r i m e s f o r w h i c h w e s i e v e o v e r a p o w e r r a t h e r t h a n o v e r t h e p r i m e i t s e l f , w e a g a i n s p l i t t h e
s u b i n t e r v a l s i n t o s m a l l e r s u b i n t e r v a l s w h i c h t i n t o t h e p r i m a r y c a c h e . T h e u s e r c a n i n s t a l l
s e v e r a l ` e a r l y a b o r t ' b o u n d s : i f t h e l e f t o v e r p a r t o f F
i
( a ; b ) a f t e r t r i a l d i v i s i o n o v e r a l l p r i m e s
b e l o w a b o u n d B < B
i
i s b i g g e r t h a n a u s e r - s p e c i e d c o n s t a n t t i m e s t h e s q u a r e o f t h e l a r g e
-
8/13/2019 An Implementation of the Number Field Sieve
12/28
7 . T h e l t e r i n g 1 0
p r i m e b o u n d , t h e n t h e p a i r ( a ; b ) i s n o t c o n s i d e r e d t o b e a c a n d i d a t e f o r a r e l a t i o n a n d i s
t h r o w n a w a y . I n t h e c a s e o f l a t t i c e s i e v i n g , t h e v a l u e s o f a w i t h a b r
1
r
1
2
m o d q a r e f a r
a w a y f r o m e a c h o t h e r f o r a x e d v a l u e o f b . O n e c a n s a v e o v e r h e a d b y m a k i n g t h e a - i n t e r v a l
l a r g e a n d t h e b - i n t e r v a l s m a l l , e . g . w e c a n t a k e b o n l y e q u a l t o 1 .
7 . T h e f i l t e r i n g
T h e a i m o f l t e r i n g i s j u s t t h e r e d u c t i o n o f t h e a m o u n t o f d a t a . W e w a n t t o n d a s u b s e t
S o f a l l r e l a t i o n s f ( a ; b ) g w h i c h w e f o u n d i n t h e s i e v i n g s t e p a n d a s u b s e t T o f t h e s e t o f
f r e e r a t i o n a l p r i m e s p , s u c h t h a t b o t h (
Q
T
p ) (
Q
S
( a b
1
) ) a n d (
Q
T
p ) (
Q
S
( a b
2
) ) a r e
s q u a r e s i n Q
n
1
] a n d Q
n
2
] , r e s p e c t i v e l y . T h e r e f o r e e v e r y a l g e b r a i c p r i m e p d i v i d i n g o n e o f
t h e p r o d u c t s (
Q
T
p
d
i
) (
Q
S
F
i
( a ; b ) ) ( i = 1 , 2 ) f o r a c e r t a i n r o o t ( r
1
: r
2
) 2 R
i
( p ) ( f r o m n o w o n
d e n o t e d b y p
( r
1
: r
2
)
) m u s t o c c u r t o a n e v e n p o w e r w i t h r e s p e c t t o t h i s r o o t . ( H e r e w e s h o u l d
s e e p
d
i
a s t h e p r o d u c t o f o n e f a c t o r p f o r e v e r y r o o t ( r
1
: r
2
) 2 R
i
( p ) ) . A p r i m e p
( r
1
: r
2
)
o c c u r s
i n a r e l a t i o n ( a ; b ) f o r p o l y n o m i a l i i f p d i v i d e s F
i
( a ; b ) a n d ( a m o d p : b m o d p ) = ( r
1
: r
2
) .
A p r i m e p
( r
1
: r
2
)
o c c u r s i n a f r e e r e l a t i o n f o r b o t h p o l y n o m i a l s i f p i s a f r e e p r i m e . W e s a y
t h a t a p r i m e p
( r
1
: r
2
)
o c c u r s i n a r e l a t i o n f o r p o l y n o m i a l i i f i t o c c u r s i n a r e l a t i o n ( a ; b ) f o r
p o l y n o m i a l i o r i f p i s a f r e e p r i m e . I t i s o b v i o u s t h a t a r e l a t i o n i n w h i c h s o m e p r i m e p
( r
1
: r
2
)
o c c u r s t o a n o d d p o w e r f o r o n e o f t h e t w o p o l y n o m i a l s i s u s e l e s s , i f t h i s p r i m e i s n o t o c c u r r i n g
i n s o m e o t h e r r e l a t i o n t o a n o d d p o w e r f o r t h e s a m e p o l y n o m i a l . T h e l t e r i n g s t a g e t h r o w s
a w a y s u c h r e l a t i o n s . I f a p r i m e p
( r
1
: r
2
)
o c c u r s t o a n o d d p o w e r i n j u s t t w o r e l a t i o n s f o r t h e
s a m e p o l y n o m i a l a n d o n e o f t h e m b e l o n g s t o t h e s e t S , t h e o t h e r o n e s h o u l d a l s o b e p a r t
o f S . I n t h e l t e r i n g s t a g e t h e t w o r e l a t i o n s a r e g r o u p e d i n t o a r e l a t i o n - s e t . I f o n e r e l a t i o n
f r o m a r e l a t i o n s e t i s c h o s e n i n t h e s e t S , t h e n a l l r e l a t i o n s f r o m t h a t r e l a t i o n - s e t s h o u l d b e i n
S . B y c r e a t i n g t h e r e l a t i o n - s e t w e h a v e e l i m i n a t e d t h e n e e d t o t a k e c a r e o f t h e p r i m e p
( r
1
: r
2
)
w h e n l o o k i n g f o r t h e s e t S . I n t h i s w a y t h e a m o u n t o f d a t a a n d t h e s i z e o f t h e m a t r i x f o r t h e
n e x t l i n e a r a l g e b r a s t e p a r e r e d u c e d .
T h e r e l a t i o n s f o u n d i n t h e s i e v i n g s t e p a r e r e a d i n s e q u e n t i a l l y . I n o r d e r t o r e g u l a t e t h e
u s e d a m o u n t o f m e m o r y t h e u s e r r s t c h o o s e s a n u m b e r o f t e m p o r a r y l e s a m o n g w h i c h t h e
d a t a w i l l b e d i s t r i b u t e d . D u r i n g t h e l t e r i n g p r o c e s s d a t a f r o m o n l y o n e t e m p o r a r y l e w i l l
b e i n t h e w o r k i n g m e m o r y o f t h e c o m p u t e r . A h a s h f u n c t i o n i s i m p l e m e n t e d w h i c h d i s t r i b u t e s
t h e p r i m e s e q u a l l y o v e r t h e n u m b e r o f t e m p o r a r y l e s . F o r a l l t h e p r i m e s i n t h e i n p u t l e
w i t h n o r m l a r g e r t h a n s o m e u s e r - d e t e r m i n e d b o u n d U m a x ( W
1
; W
2
) a n d o c c u r r i n g t o a n
o d d p o w e r i n o n e o f t h e F
i
( a ; b ) , t h e l t e r p r o g r a m c a l c u l a t e s t h e i n d e x o f t h e c o r r e s p o n d i n g
t e m p o r a r y l e b y u s i n g t h e h a s h f u n c t i o n o n t h e p r i m e . T h e r e l a t i o n i s w r i t t e n t o t h e l e w i t h
t h e s m a l l e s t n u m b e r i t g e t s f r o m a l l t h e s e p r i m e s . W e s t o r e a , b a n d t h e p r i m e s w h i c h w e r e
w r i t t e n i n t h e i n p u t l e . E x t r a f e a t u r e s i n t h i s p r o g r a m h a v e b e e n a d d e d , s u c h a s l o o k i n g
o n l y a t t h e p r i m e s b e l o w s o m e u s e r - d e t e r m i n e d b o u n d a n d t h r o w i n g a w a y a l l t h e r e l a t i o n s
c o n t a i n i n g a p r i m e w h i c h i s b i g g e r t h a n s o m e u s e r - d e t e r m i n e d b o u n d .
W h e n a l l r e l a t i o n s a r e r e a d i n a n d s t o r e d i n t h e c o r r e s p o n d i n g l e s , t h e c o m b i n i n g a n d
t h r o w i n g o u t p r o c e s s s t a r t s . F i r s t a l l r e l a t i o n s ( a ; b ) o f t h e r s t l e a r e r e a d i n a n d s t o r e d i n a
h e a p 2 3 , x 3 . 7 . 1 ] i n a d e s c e n d i n g o r d e r a c c o r d i n g t o t h e l a r g e s t p r i m e w h i c h l e d t o t h e s t o r a g e
o f t h e r e l a t i o n i n t h i s l e . W e s t a r t w i t h c o n s i d e r i n g t h e r e l a t i o n s i n w h i c h t h e l a r g e s t p r i m e p
c o r r e s p o n d i n g t o t h i s l e o c c u r . W e c a l c u l a t e t h e r o o t ( r
1
: r
2
) f o r t h i s p r i m e f o r t h e r e l a t i o n s
( a ; b ) b y c a l c u l a t i n g ( a m o d p : b m o d p ) . I f t h e r e a p p e a r d
1
+ d
2
d i e r e n t r o o t s f o r t h i s p r i m e
i n t h e s e r e l a t i o n s , w e a p p e n d t h e f r e e r e l a t i o n f o r t h i s p r i m e . I f w h i l e l o o k i n g a t a p r i m e
-
8/13/2019 An Implementation of the Number Field Sieve
13/28
8 . T h e b l o c k L a n c z o s m e t h o d 1 1
p
( r
1
: r
2
)
w e s e e t h e s a m e r e l a t i o n ( a ; b ) t w i c e , w e t h r o w o u t o n e o f t h e r e l a t i o n s . I f s o m e p r i m e
p
( r
1
: r
2
)
o c c u r s e x a c t l y o n c e f o r o n e o f t h e p o l y n o m i a l s , t h e n t h e c o r r e s p o n d i n g r e l a t i o n i s
t h r o w n o u t . I f a p r i m e p
( r
1
: r
2
)
o c c u r s t w i c e f o r o n e o f t h e p o l y n o m i a l s , t h e t w o c o r r e s p o n d i n g
r e l a t i o n s a r e g r o u p e d i n a r e l a t i o n - s e t . I f t h e u s e r w i s h e s , f o r p r i m e s p
( r
1
: r
2
)
w h i c h o c c u r j u s t
t h r e e t i m e s f o r o n e o f t h e p o l y n o m i a l s , t h e p r o g r a m r e p l a c e s t h e t h r e e c o r r e s p o n d i n g r e l a t i o n s
b y t w o r e l a t i o n - s e t s o f t w o r e l a t i o n s e a c h .
N e x t t h e r e s u l t i n g r e l a t i o n - s e t s a n d t h e r e l a t i o n s w h i c h w e r e n o t c o m b i n e d a r e s t o r e d a t t h e
n e x t ` p l a c e ' c o r r e s p o n d i n g t o t h e h a s h f u n c t i o n . I f t h e r e l a t i o n o r r e l a t i o n - s e t c o n t a i n s s m a l l e r
p r i m e s t o a n o d d p o w e r w h i c h c o r r e s p o n d t o t h e s a m e l e , w e k e e p t h e r e l a t i o n ( - s e t ) i n t h e
w o r k i n g m e m o r y . W e s t o r e t h e r e l a t i o n ( - s e t ) i n t h e h e a p a c c o r d i n g t o t h e l a r g e s t o f t h o s e
p r i m e s . O t h e r w i s e , i f t h e r e l a t i o n ( - s e t ) c o n t a i n s p r i m e s t o a n o d d p o w e r w h i c h c o r r e s p o n d
t o o t h e r l e s , w e s t o r e t h e r e l a t i o n ( - s e t ) i n t h e l e a m o n g t h o s e w i t h t h e s m a l l e s t n u m b e r
e x c e e d i n g t h e n u m b e r o f t h e l e w h i c h w e c u r r e n t l y h a v e i n m e m o r y , o r , i f t h e r e i s n o t s u c h
a l e , i n t h e l e a m o n g t h o s e w i t h t h e s m a l l e s t n u m b e r . I f t h e r e l a t i o n ( - s e t ) o n l y c o n t a i n s
l a r g e r p r i m e s t o a n o d d p o w e r w h i c h c o r r e s p o n d t o t h e s a m e l e , w e k e e p t h e r e l a t i o n ( - s e t ) i n
t h e s a m e l e , b u t w r i t e i t t o d i s k . I f t h e r e l a t i o n ( - s e t ) d o e s n o t c o n t a i n a n y p r i m e s l a r g e r t h a n
W
i
t o a n o d d p o w e r a n y m o r e , w e w r i t e i t t o a n o u t p u t l e . T h i s c i r c u l a r q u e u e i s c o n s t r u c t e d
s u c h t h a t , w h e n t r y i n g t o t h r o w o u t r e l a t i o n ( - s e t ) s o r c o m b i n i n g r e l a t i o n ( - s e t ) s i n t o ( n e w )
r e l a t i o n - s e t s f o r s o m e p r i m e p , a l l r e l a t i o n ( - s e t ) s c o n t a i n i n g t h a t p r i m e t o a n o d d p o w e r w i l l
b e c o n s i d e r e d . W h e n w e s t o r e a r e l a t i o n - s e t w e s t o r e a l l r e l a t i o n s i t c o n t a i n s , t o g e t h e r w i t h
t h e i r p r i m e s e x c e e d i n g W
i
a n d t h e f r e e p r i m e s o f t h e r e l a t i o n - s e t .
A f t e r t h e r s t t e m p o r a r y l e i s t r e a t e d i n t h i s w a y t h e s a m e p r o c e s s t a k e s p l a c e c o n s e c u t i v e l y
w i t h t h e o t h e r l e s . O f c o u r s e , r e l a t i o n - s e t s c a n a l s o b e c o m b i n e d w i t h e a c h o t h e r . R e l a t i o n -
s e t s w h i c h b e c o m e t o o ` h e a v y ' , i . e . , c o n t a i n m o r e r e l a t i o n s t h a n a u s e r - d e t e r m i n e d b o u n d , a r e
t h r o w n a w a y , i n a n a t t e m p t t o k e e p t h e m a t r i x f o r t h e n e x t l i n e a r a l g e b r a s t e p s p a r s e . T h e
u s e r c a n x t h e m a x i m u m n u m b e r o f r e l a t i o n - s e t s w h i c h c a n b e t h r o w n a w a y . W h e n t h e l a s t
l e h a s b e e n p r o c e s s e d t h e p r o g r a m s t a r t s a g a i n a t t h e r s t l e , u n t i l n o c h a n g e s h a v e t a k e n
p l a c e i n t h e l a s t r o u n d o r t h e n u m b e r o f p a s s e s h a s r e a c h e d a u s e r - c h o s e n b o u n d . T h e n a l l
r e l a t i o n ( - s e t ) s w h i c h a r e s t i l l i n t h e t e m p o r a r y l e s a r e w r i t t e n t o t h e o u t p u t l e .
T h e l t e r p r o g r a m c o u n t s t h e n u m b e r o f r e l a t i o n s a n d r e l a t i o n - s e t s w h i c h r e m a i n a n d t h e
n u m b e r o f p r i m e s p
( r
1
: r
2
)
o c c u r r i n g t o a n o d d p o w e r i n o n e o f t h e r e l a t i o n s o r r e l a t i o n - s e t s w i t h
n o r m l a r g e r t h a n U . F r o m t h e s e d a t a o n e c a n e s t i m a t e w h e t h e r t h e r e a r e e n o u g h r e l a t i o n s .
I n p r a c t i c e w e u s e d l t e r s e v e r a l t i m e s f o r o n e n u m b e r . T o s a v e d i s k s p a c e w e c h o s e
b i g p r i n t i n g b o u n d s , W
1
= W
2
= 1 0
6
, s a y . F i r s t w e a p p l i e d t h e l t e r p r o g r a m t o t h e
o u t p u t o f t h e s i e v i n g s t e p w i t h U = W
1
. O n t h e r e m a i n i n g r e l a t i o n ( - s e t ) s w e a p p l i e d t h e
p r o g r a m f a c t o r r e l a t i o n s t o c o m p u t e t h e p r i m e f a c t o r s b e t w e e n a s m a l l e r b o u n d W
0
a n d W
i
o f F
1
( a ; b ) a n d F
2
( a ; b ) f o r a l l r e l a t i o n s ( a ; b ) a n d s t o r e t h e r e l a t i o n ( - s e t ) s , n o w w i t h a l l p r i m e s
e x c e e d i n g W
0
. T h e n w e a g a i n a p p l i e d t h e l t e r p r o g r a m , n o w o n a l l p r i m e s e x c e e d i n g U
0
,
w i t h W
0
U
0
< U . T h e s e s t e p s w e r e r e p e a t e d u n t i l w e r e a c h e d a b o u n d b e l o w w h i c h m a n y
p r i m e s o c c u r a t l e a s t f o u r t i m e s , s o n o c o m b i n i n g o r t h r o w i n g o u t c o u l d b e d o n e , o r u n t i l w e
w e r e c o n t e n t w i t h t h e r e s u l t i n g m a t r i x s i z e .
8 . T h e b l o c k L a n c z o s m e t h o d
A f t e r e n o u g h r e l a t i o n s h a v e b e e n c o l l e c t e d a n d t h e l t e r p r o g r a m h a s r e d u c e d t h e a m o u n t
o f d a t a , w e t r y t o n d a s u b s e t S o f t h e r e l a t i o n s w h i c h a r e l e f t a f t e r t h e l t e r i n g s t a g e a n d
-
8/13/2019 An Implementation of the Number Field Sieve
14/28
-
8/13/2019 An Implementation of the Number Field Sieve
15/28
8 . T h e b l o c k L a n c z o s m e t h o d 1 3
s i z e . I n s p i r e d b y w o r k o f C o p p e r s m i t h 6 ] , M o n t g o m e r y 1 7 ] i m p l e m e n t e d t h e b l o c k L a n c z o s
m e t h o d w h i c h e x p l o i t s t h i s a d v a n t a g e .
T h e b l o c k L a n c z o s a l g o r i t h m g e n e r a t e s a s e q u e n c e o f s u b s p a c e s W
i
i n s t e a d o f t h e v e c -
t o r s f w
i
g . A p p l y i n g s t a n d a r d L a n c z o s o v e r F
2
g i v e s t h e p r o b l e m t h a t i n a p p r o x i m a t e l y h a l f
o f t h e c a s e s t h e r e q u i r e m e n t w
T
i
A w
i
6= 0 i f w
i
6= 0 i s v i o l a t e d . I n t h e b l o c k L a n c z o s a l g o r i t h m
t h e a n a l o g o u s r e q u i r e m e n t i s t h a t n o n o n z e r o v e c t o r i n W
i
i s A - o r t h o g o n a l t o W
i
. T h i s w i l l
h o l d w h e n W
T
i
A W
i
i s i n v e r t i b l e , w h e r e W
i
i s a m a t r i x w h o s e c o l u m n v e c t o r s s p a n W
i
.
W i t h A a s y m m e t r i c k k m a t r i x o v e r a e l d K a n d V
0
a n a r b i t r a r y k N m a t r i x , t h e
b l o c k L a n c z o s a l g o r i t h m i t e r a t e s , f o r i = 0 ; 1 ; : : :
W
i
= V
i
S
i
( 8 . 1 0 )
C
i + 1 ; j
= ( W
T
j
A W
j
)
1
W
T
j
A ( A W
i
S
T
i
+ V
i
) ( 0
j
i ) ;
V
i + 1
= A W
i
S
T
i
+ V
i
i
X
j = o
W
j
C
i + 1 ; j
: ( 8 . 1 1 )
I n ( 8 . 1 0 ) t h e N N
i
m a t r i x S
i
( N
i
N ) c o n s i s t s o f z e r o s e x c e p t f o r e x a c t l y o n e 1 p e r c o l u m n
a n d a t m o s t o n e 1 p e r r o w , t h u s s e l e c t i n g c o l u m n s f r o m V
i
f o r W
i
. W e c h o o s e t h e c o l u m n s
o f V
i
s u c h t h a t t h e c o r r e s p o n d i n g c o l u m n s o f V
T
i
A V
i
a r e a l i n e a r l y i n d e p e n d e n t s p a n n i n g
s e t o f a l l c o l u m n s o f V
T
i
A V
i
. T h u s N
i
= r a n k ( V
T
i
A V
i
) a n d o n e c a n p r o v e t h a t t h e r e s u l t i n g
W
T
i
A W
i
i s i n v e r t i b l e . T h e i t e r a t i o n p r o c e s s s t o p s w h e n V
T
i
A V
i
= O , f o r i = l s a y .
I f V
l
= O t h e f o l l o w i n g h o l d :
W
T
i
A W
i
i s i n v e r t i b l e ( 0 i < l ) ;
W
T
j
A W
i
= O ( i 6= j ) ; ( 8 . 1 2 )
W
T
j
A V
i
= O ( 0
j < i
l ) ; ( 8 . 1 3 )
A
W Ww h e r e
W= s p a n (
W
0
;
W
1
; : : : ;
W
l 1
) :
a n d i f b 2 W o n e c a n d e d u c e t h a t t h e v e c t o r
x =
P
l 1
i = 0
W
i
( W
T
i
A W
i
)
1
W
T
i
b
i s a s o l u t i o n o f A x = b .
I f w e c a n c h o o s e S
i
s u c h t h a t s p a n ( V
i
) s p a n ( W
0
; W
1
; : : : ; W
i + 1
) , t h e n i t i s p o s s i b l e t o
s i m p l i f y t h e c a l c u l a t i o n o f V
i + 1
i n ( 8 . 1 1 ) i n a s i m i l a r w a y a s t h e c a l c u l a t i o n o f w
i
i n ( 8 . 8 ) w a s
s i m p l i e d t o ( 8 . 9 )
V
i + 1
= A W
i
S
T
i
+ V
i
W
i
C
i + 1 ; i
W
i 1
C
i + 1 ; i 1
W
i 2
C
i + 1 ; i 2
( i 2 ) : ( 8 . 1 4 )
T h e r e q u i r e m e n t i s f u l l l e d w h e n t h e c o l u m n s o f V
i
a r e i n s p a n ( W
i
; W
i + 1
) . F r o m ( 8 . 1 4 ) w e
c a n d e d u c e t h a t
V
i + 1
= A W
i
S
T
i
+ V
i
W
w h e r e W i s a k N m a t r i x , w h o s e c o l u m n s a r e l i n e a r c o m b i n a t i o n s o f t h e c o l u m n s o f W
i
,
W
i 1
a n d W
i 2
. N o t i c e t h a t t h e c o l u m n s w h i c h w e r e n o t s e l e c t e d f r o m V
i
a r e z e r o i n S
T
i
-
8/13/2019 An Implementation of the Number Field Sieve
16/28
8 . T h e b l o c k L a n c z o s m e t h o d 1 4
a n d i n A W
i
S
T
i
a s w e l l . T h e r e f o r e a n o n - s e l e c t e d c o l u m n o f V
i
i s e q u a l t o t h e s u m o f t h e
c o r r e s p o n d i n g c o l u m n s o f V
i + 1
a n d W . U s i n g ( 8 . 1 3 ) a n d ( 8 . 1 2 ) w e c a n d e d u c e t h a t s u c h a
c o l u m n o f W m u s t b e a l i n e a r c o m b i n a t i o n o f t h e c o l u m n s o f W
i
o n l y . C h o o s i n g t h e c o l u m n s
o f V
i + 1
w h i c h w e r e n o t s e l e c t e d i n V
i
g u a r a n t e e s t h a t t h e n o n - s e l e c t e d c o l u m n s o f V
i
a r e i n
s p a n (
W
i
;
W
i + 1
) . I f t h e s e c o l u m n s o f V
i
a r e i n d e p e n d e n t b u t t h e c o r r e s p o n d i n g c o l u m n s o f
V
T
i + 1
A V
i + 1
a r e d e p e n d e n t w e c a n n o t f u l l l t h e r e q u i r e m e n t t h a t W
T
i + 1
A W
i + 1
i s i n v e r t i b l e ,
a n d t h e a l g o r i t h m f a i l s . I n p r a c t i c e t h i s n e v e r h a p p e n e d . O t h e r w i s e w e c h o o s e a s p a n n i n g s e t
o f c o l u m n s f o r V
T
i + 1
A V
i + 1
i n c l u d i n g t h e c o l u m n s w h i c h w e r e n o t s e l e c t e d f o r V
i
, a n d c h o o s e
S
i + 1
a c c o r d i n g l y .
W h e n w e w a n t t o a p p l y t h e b l o c k L a n c z o s m e t h o d t o o u r m a t r i x M , w e h a v e t o d e a l w i t h
s e v e r a l o b s t r u c t i o n s . F i r s t M n e e d n o t b e s y m m e t r i c a n d t h e r e f o r e w e a p p l y t h e a l g o r i t h m
t o t h e s y m m e t r i c m a t r i x A = M
T
M . I t i s o b v i o u s t h a t a n y s o l u t i o n o f M x = 0 s a t i s e s
A x = 0 , b u t t h e c o n v e r s e n e e d n o t b e t r u e . S e c o n d l y , i f w e w a n t t o n d a v e c t o r f r o m t h e
n u l l s p a c e o f A a n d s t a r t w i t h b = 0 , w e w i l l n d t h e t r i v i a l s o l u t i o n x = 0 . W e o v e r c o m e
t h i s p r o b l e m b y s t a r t i n g w i t h a r a n d o m v e c t o r y a n d t a k i n g b = A y . W h e n x i s a s o l u t i o n o f
A x = b = A y , t h e n x y w i l l b e a r a n d o m v e c t o r f r o m t h e n u l l s p a c e o f A . T h i r d l y , s e v e r a l
v e c t o r s f r o m t h e n u l l s p a c e o f M h a v e t o b e f o u n d , s i n c e n o t e v e r y d e p e n d e n c y c o r r e s p o n d i n g
w i t h s u c h a v e c t o r w i l l l e a d t o a n o n - t r i v i a l f a c t o r o f n . N o t e t h a t d u r i n g t h e i t e r a t i o n s t e p s
t h e v e c t o r b o n l y i s i n v o l v e d i n t h e c a l c u l a t i o n o f t h e s o l u t i o n v e c t o r x . T h e r e f o r e r e p l a c i n g b
b y a k N m a t r i x B i n t h e c a l c u l a t i o n o f x w i l l g i v e a s o l u t i o n o f A X = B , w i t h X a l s o a
k N m a t r i x . T o n d s e v e r a l v e c t o r s i n t h e n u l l s p a c e o f A w e s t a r t w i t h a r a n d o m k N
m a t r i x Y a n d c a l c u l a t e s o l u t i o n s o f A X = A Y . T h e N c o l u m n v e c t o r s o f X Y w i l l b e
r a n d o m v e c t o r s i n t h e n u l l s p a c e o f A a n d w e e x t r a c t t h e o n e s w h i c h a r e a l s o i n t h e n u l l s p a c e
o f M .
F i n a l o b s t r u c t i o n s a r e t h e t w o r e q u i r e m e n t s f o r x t o b e a s o l u t i o n o f A x = b . F i r s t b h a s
t o b e i n W = s p a n ( W
0
; W
1
; : : : ; W
l 1
) . T h i s c a n b e a r r a n g e d b y i n i t i a l i z i n g V
0
a s A Y w h e r e
Y i s a r a n d o m k N m a t r i x . S e c o n d l y , t h e a l g o r i t h m o f t e n t e r m i n a t e s w i t h V
T
l
A V
l
= O
b u t V
l
6= O . M o n t g o m e r y p r e s u m e s t h a t t h e c o l u m n v e c t o r s o f A ( X Y ) a n d A V
l
a r e b o t h
i n s p a n ( V
l
) , w h i c h h a s m a x i m a l r a n k N , b u t i n p r a c t i c e t h e r a n k i s m u c h s m a l l e r . W e m a y
e x p e c t t h a t s o m e l i n e a r c o m b i n a t i o n s o f t h e s e v e c t o r s a r e i n t h e n u l l s p a c e o f A . C o m b i n e d
w i t h t h e n e e d t o n d v e c t o r s i n t h e n u l l s p a c e o f M i n s t e a d o f A , i t s u c e s t o c o n s t r u c t a
s u i t a b l e m a t r i x U s u c h t h a t M Z U = O , w h e r e Z i s a k 2 N m a t r i x o f t h e c o l u m n s o f
X Y a n d V
l
. W e r s t c o m p u t e M Z . T h e n w e d e t e r m i n e a m a t r i x U w h o s e c o l u m n s s p a n
t h e n u l l s p a c e o f M Z . T h e o u t p u t i s a b a s i s f o r Z U .
F o r i m p l e m e n t i n g t h e c a l c u l a t i o n o f V
i + 1
i n ( 8 . 1 4 ) o n e c a n b r i n g f u r t h e r d o w n t h e n u m b e r
o f c a l c u l a t i o n s b y u s i n g t h e f o l l o w i n g s t e p s : f o r i = 0 ; 1 ; : : :
V
i + 1
= A V
i
S
i
S
T
i
+ V
i
D
i + 1
+ V
i 1
E
i + 1
+ V
i 2
F
i + 1
; w h e r e
D
i + 1
= I
N
W
i
( V
T
i
A
2
V
i
S
i
S
T
i
+ V
T
i
A V
i
) ;
W
i
= S
i
( S
T
i
V
T
i
A V
i
S
i
)
1
S
T
i
;
E
i + 1
= W
i 1
V
T
i
A V
i
S
i
S
T
i
;
F
i + 1
= W
i 2
( I
N
V
T
i 1
A V
i 1
W
i 1
)
( V
T
i 1
A
2
V
i 1
S
i 1
S
T
i 1
+ V
T
i 1
A V
i 1
) S
i
S
T
i
a n d w h e r e , f o r i
-
8/13/2019 An Implementation of the Number Field Sieve
17/28
9 . E x t r a c t i n g t h e s q u a r e r o o t 1 5
F
i + 1
= O a n d t h e t e r m V
i 2
F
i + 1
i n t h e e x p r e s s i o n f o r V
i + 1
c a n b e o m i t t e d .
F o r l a r g e , s p a r s e m a t r i c e s t h e s t o r a g e r e q u i r e m e n t o f L a n c z o s ' a l g o r i t h m i s s u p e r i o r t o t h a t
o f G a u s s i a n e l i m i n a t i o n . I t o n l y n e e d s t h e o r i g i n a l m a t r i x a n d s o m e e x t r a v e c t o r s o f l e n g t h k
a n d s o m e N N m a t r i c e s , w h i l e G a u s s i a n e l i m i n a t i o n c a u s e s l l - i n a n d t h e r e f o r e n e e d s
a p p r o x i m a t e l y k
2
b i t s . W h e n M h a s d n o n z e r o e n t r i e s p e r r o w o n a v e r a g e , t h e t i m e n e e d e d
b y b l o c k L a n c z o s i s O ( d k
2
= N ) + O ( k
2
) . W h e n d i s m u c h s m a l l e r t h a n k t h i s i s c o n s i d e r a b l y
b e t t e r t h a n O ( k
3
= N ) f o r G a u s s i a n e l i m i n a t i o n .
I n p r a c t i c e w e m a k e M e x t r a s p a r s e b y n o t a p p e n d i n g a n y c h a r a c t e r r o w s . I f M i s a k
1
k
2
m a t r i x , t h e o u t p u t o f t h e b l o c k L a n c z o s a l g o r i t h m w i l l c o n s i s t o f a k
2
N m a t r i x P w i t h N
` p s e u d o - d e p e n d e n c i e s ' o f w h i c h w e s t i l l h a v e t o n d l i n e a r c o m b i n a t i o n s t o g e t a s e t S w e l o o k
f o r . W e s o l v e t h i s p r o b l e m h e r e , a l t h o u g h i n o u r i m p l e m e n t a t i o n i t i s a p a r t o f t h e s q u a r e
r o o t p r o g r a m . F o r s e v e r a l q u a d r a t i c c h a r a c t e r s ( q ; ( s
1
: s
2
) ) | c h o s e n a s d e s c r i b e d i n S e c t i o n 2
w i t h q l a r g e r t h a n a n y p r i m e d i v i d i n g a n y F
i
( a ; b ) | w e f o r m a v e c t o r q
( q ; ( s
1
: s
2
) )
o f l e n g t h k
2
b y i n s e r t i n g a z e r o f o r a l l o f t h e k
2
r e l a t i o n - s e t s V w i t h
Q
V
p
p
q
Q
V
f
a b ( s
1
s
1
2
m o d q )
q
= 1
a n d a o n e o t h e r w i s e . A v e c t o r o f l e n g t h N o r t h o g o n a l t o a l l v e c t o r s q
( q ; ( s
1
: s
2
) )
P i s i n d i c a t i n g a
l i n e a r c o m b i n a t i o n o f t h e N p s e u d o - d e p e n d e n c i e s w h i c h i s f a v o u r a b l e t o a l l c h o s e n q u a d r a t i c
c h a r a c t e r s . W e c o n s t r u c t a b a s i s f o r t h e s p a c e o r t h o g o n a l t o a l l v e c t o r s q
( q ; ( s
1
: s
2
) )
P . E a c h o f
t h e s e b a s i s v e c t o r s i n d i c a t e s w h i c h p s e u d o - d e p e n d e n c i e s o f P s h o u l d b e c o m b i n e d f o r a r e a l
d e p e n d e n c y , t h e r e b y i n d i c a t i n g a s e t S .
9 . E x t r a c t i n g t h e s q u a r e r o o t
I n t h e n a l s t a g e w e h a v e t w o s q u a r e s
2
= (
Q
p 2 T
p ) (
Q
( a ; b ) 2 S
( a b
1
) ) a n d
2
= (
Q
p 2 T
p )
(
Q
( a ; b ) 2 S
( a b
2
) ) i n Q
n
1
] a n d Q
n
2
] , r e s p e c t i v e l y . W e h a v e t o c a l c u l a t e a n d . I f w e
w r i t e b o t h s q u a r e s a s p o l y n o m i a l s o f d e g r e e l e s s t h a n d
i
i n
i
, t h e n t h e c o e c i e n t s w i l l b e
g i g a n t i c . T h e n a c o n v e n t i o n a l m e t h o d a s d e s c r i b e d i n 5 , x 3 . 6 . 2 ] c a n n o t b e u s e d . C o u v e i g n e s
7 ] c a l c u l a t e s t h e s q u a r e r o o t s m o d u l o s e v e r a l p r i m e s a n d a p p l i e s t h e C h i n e s e R e m a i n d e r
T h e o r e m . H i s m e t h o d p r e s e n t l y w o r k s o n l y f o r n u m b e r e l d s o f o d d d e g r e e .
M o n t g o m e r y 1 6 ] a t t a c k s t h e p r o b l e m b y a n i t e r a t i v e p r o c e s s . H e s t a r t s b y p a r t i t i o n i n g
t h e s e t S i n t w o s u b s e t s S
1
a n d S
2
a n d t h e s e t T i n t w o s u b s e t s T
1
a n d T
2
t o a d v a n c e t h e
c a n c e l l a t i o n o f p r i m e s p
( r
1
: r
2
)
i n b o t h p r o d u c t s ( i = 1 ; 2 )
Q
p 2 T
1
p
d
i
Q
( a ; b ) 2 S
1
F
i
( a ; b )
Q
p 2 T
2
p
d
i
Q
( a ; b ) 2 S
2
F
i
( a ; b )
: ( 9 . 1 5 )
H e r e , t h e e x p r e s s i o n s p
d
i
f o r t h e f r e e p r i m e s p 2 f T
1
T
2
g s h o u l d b e s e e n a s t h e p r o d u c t o f
o n e f a c t o r p f o r e v e r y r o o t ( r
1
: r
2
) 2 R
i
( p ) . W e c a n f o r e x a m p l e c h o o s e S
1
= S , S
2
e m p t y ,
T
1
= T a n d T
2
e m p t y o r w e c a n d i s t r i b u t e S a n d T o v e r t h e s e t s S
j
a n d T
j
r a n d o m l y . A t t h e
e n d o f t h i s S e c t i o n w e w i l l s e e h o w w e t r i e d t o o p t i m i z e t h i s s e l e c t i o n . L e t
(
1
)
2
=
Q
T
1
p
Q
S
1
( a b
1
)
Q
T
2
p
Q
S
2
( a b
1
)
a n d (
2
)
2
=
Q
T
1
p
Q
S
1
( a b
2
)
Q
T
2
p
Q
S
2
( a b
2
)
t h e n w e w i l l c a l c u l a t e
1
a n d
2
, f o r w h i c h t h e c o n g r u e n c e (
1
(
1
) )
2
(
2
(
2
) )
2
m o d n h o l d s .
T h e f o l l o w i n g a l g o r i t h m i s a p p l i e d t w i c e , r s t t o c a l c u l a t e =
1
a n d t h e n t o c a l c u l a t e =
2
.
I n t h e r e s t o f t h i s S e c t i o n w e s u p p r e s s t h e i n d e x i w h e n r e f e r r i n g t o
i
, f
i
, d
i
, c
i ; k
a n d
i
.
-
8/13/2019 An Implementation of the Number Field Sieve
18/28
9 . E x t r a c t i n g t h e s q u a r e r o o t 1 6
S t a r t i n g w i t h
1
=
2
, w h e r e i s u n k n o w n , w e w i l l a p p r o x i m a t e i n i t e r a t i o n s t e p j ( j 1 )
t h e n u m e r a t o r ( i f j i s o d d ) o r t h e d e n o m i n a t o r ( i f j i s e v e n ) o f
p
j
b y
j
( t o b e e x p l a i n e d
b e l o w ) a n d c a l c u l a t e
j + 1
b y
j + 1
=
j
(
2
j
)
( 1 )
j
( j 1 ) : ( 9 . 1 6 )
H e n c e
2
=
j + 1
Q
b
j + 1
2
c
l = 1
2
2 l 1
Q
b
j
2
c
l = 1
2
2 l
: ( 9 . 1 7 )
T h e p r o d u c t o f t h e n o r m s o f t h e n u m e r a t o r a n d t h e d e n o m i n a t o r o f
j + 1
i n ( 9 . 1 7 ) w i l l d e -
c r e a s e a t e v e r y i t e r a t i o n s t e p . S m a l l n o r m s o f n u m e r a t o r a n d d e n o m i n a t o r , h o w e v e r , d o n o t
g u a r a n t e e t h a t t h e c o e c i e n t s o f
j + 1
a s a p o l y n o m i a l o f d e g r e e d 1 i n a r e s m a l l . L e t
1
;
2
; : : : ;
d
b e t h e c o n j u g a t e s o f . F o r a n y p o l y n o m i a l h ( x ) 2 Q x ] o f d e g r e e a t m o s t d 1
w e c a n w r i t e ( L a g r a n g e i n t e r p o l a t i o n f o r m u l a )
h ( x ) =
d 1
X
k = 0
x
k
d
X
l = 1
h (
l
) c
k l
;
w h e r e t h e c
k l
c a n b e c a l c u l a t e d f r o m
f ( x )
( x
l
) f
0
(
l
)
=
d 1
X
k = 0
c
k l
x
k
:
T h e r e f o r e w e c a n b o u n d t h e c o e c i e n t s o f h ( x ) i n t e r m s o f t h e j h (
l
) j . W e u s e t h i s o b s e r v a t i o n
b y c h o o s i n g t h e a p p r o x i m a t i o n
j
i n s u c h a w a y t h a t n o t o n l y t h e p r o d u c t o f t h e n u m e r a t o r
a n d t h e d e n o m i n a t o r n o r m s o f t h e s u c c e s s i v e
j + 1
' s d e c r e a s e s , b u t a l s o j
j + 1
(
l
) j t e n d s t o
d e c r e a s e f o r a l l l . W h e n t h e n o r m s a n d t h e e m b e d d i n g s b e c o m e s m a l l e n o u g h , w e w i l l e x p r e s s
t h e n a l
j + 1
a s a p o l y n o m i a l o f d e g r e e d 1 i n a n d n d i t s s q u a r e r o o t b y u s i n g t h e
c o m p u t e r p a c k a g e P A R I 2 ] .
I n o r d e r t o n d t h e
j
' s w e w o r k w i t h i d e a l s . D e n o t e b y O t h e r i n g o f i n t e g e r s i n Q ] a n d
f o r x
j
2 Q ] b y < x
1
; : : : ; x
n
> O t h e f r a c t i o n a l i d e a l g e n e r a t e d b y x
1
; : : : ; x
n
i n O . S u p p o s e
O =
Q
l 2 L
j 1
P
c
l
l
Q
l 2 L
j 2
P
c
l
l
: ( 9 . 1 8 )
i s t h e f a c t o r i z a t i o n o f O i n t o p r i m e i d e a l s P
l
o f O , w h e r e c
l
2 Z
+
f o r a l l l . A t e a c h
i t e r a t i o n s t e p w e s e l e c t a n i d e a l I d i v i d i n g t h e n u m e r a t o r ( i f j i s o d d ) o r t h e d e n o m i n a t o r
( i f j i s e v e n ) o f ( 9 . 1 8 ) . T h e a p p r o x i m a t i o n
j
w i l l b e a ` s m a l l ' e l e m e n t o f I . I f I d i v i d e s
t h e n u m e r a t o r , w e d i v i d e O b y <
j
> O a n d t h i s w i l l r e s u l t i n t h e d i s a p p e a r a n c e o f
I i n t h e n u m e r a t o r o f O a n d t h e a p p e a r a n c e o f a n e w i n t e g r a l i d e a l Q o f O i n t h e
d e n o m i n a t o r o f O . I f I d i v i d e s t h e d e n o m i n a t o r t h e c o n v e r s e h a p p e n s . I f N ( I ) i s
s u c i e n t l y l a r g e , t h a n N ( Q ) w i l l b e m u c h s m a l l e r t h a n N ( I ) . I n t h i s w a y t h e p r o d u c t o f t h e
n u m e r a t o r a n d t h e d e n o m i n a t o r n o r m s w i l l d e c r e a s e e v e r y i t e r a t i o n s t e p .
T o f a c t o r <
j
> O i n t o p r i m e i d e a l s , w e u s e t h e i d e a l
-
8/13/2019 An Implementation of the Number Field Sieve
19/28
9 . E x t r a c t i n g t h e s q u a r e r o o t 1 7
J = < c
d
; c
d
+ c
d 1
; c
d
2
+ c
d 1
+ c
d 2
; : : : ; c
d
d 1
+ c
d 1
d 2
+ + c
1
> O :
W e h a v e 1 6 ]
J O
O J = O : ( 9 . 1 9 )
F r o m ( 9 . 1 9 ) w e d e d u c e < a b > O J O . T h e r e f o r e , i f w e m u l t i p l y a n i d e a l < a b > O b y
J w e c a n f a c t o r t h e r e s u l t i n p r i m e i d e a l s , a l l w i t h a p o s i t i v e e x p o n e n t . T h e i d e a l s < p > O
w i t h p
2 Ta r e a l r e a d y i n t e g r a l , s o m u l t i p l i c a t i o n w i t h
Ji s n o t n e c e s s a r y f o r t h e s e i d e a l s .
W e s t a r t w i t h
<
1
> O =
J
# S
2
Q
T
1
< p > O
Q
S
1
f < a b > O J g
J
# S
1
Q
T
2
< p >
O
Q
S
2
f< a
b >
O J g
( 9 . 2 0 )
a n d f a c t o r t h e i d e a l s < p >
Oa n d < a
b >
O Ji n t o p r i m e i d e a l s . T h e r e f o r e w e s p l i t t h e
p r i m e s i n t w o s u b s e t s : t h e s e t o f ` s p e c i a l ' p r i m e s w h i c h d i v i d e t h e i n d e x
O: Z ] ] a n d t h e
r e m a i n i n g p r i m e s w h i c h w e c a l l n o r m a l . T o e v e r y p r i m e p a n d e v e r y r o o t ( r
1
: r
2
) 2 R ( p ) t h e r e
c o r r e s p o n d p r i m e i d e a l s d i v i d i n g < p > O i f p i s a n e l e m e n t o f T
1
T
2
o r d i v i d i n g < a b > O J
i f p d i v i d e s F ( a ; b ) ( ( a ; b ) 2 S
1
S
2
) . F o r a s p e c i a l p r i m e t h e r e m a y e x i s t m o r e p r i m e i d e a l s
c o r r e s p o n d i n g t o t h e s a m e r o o t , b u t f o r a n o r m a l p r i m e p t h e p r i m e i d e a l P c o r r e s p o n d i n g t o
a r o o t ( r
1
: r
2
) 2 R ( p ) i s u n i q u e l y d e t e r m i n e d . B a s e d o n p r a c t i c a l e x p e r i e n c e M o n t g o m e r y
s u s p e c t s | w h i c h w e c a n n o t p r o v e | t h a t i n t h e l a t t e r c a s e t h e c o r r e s p o n d e n c e i s g i v e n b y
P =
8
>
:
< p ; c
d
c
d
r
1
r
1
2
m o d p > O i f p 6 j c
d
< p > O + J i f p j c
d
a n d r
2
= 0
J < p ; r
1
r
1
2
m o d p > O i f p j c
d
a n d r
2
6= 0 :
( 9 . 2 1 )
F o r t h e s p e c i a l p r i m e s p a n d f o r a l l t h e i r r o o t s ( r
1
: r
2
) 2 R ( p ) , w e c a l c u l a t e t h e i d e a l P
u s i n g ( 9 . 2 1 ) a n d f a c t o r i t i n t o p r i m e i d e a l s w i t h h e l p o f t h e c o m p u t e r p a c k a g e P A R I . W h i l e
w e r e a d i n t h e f r e e p r i m e s a n d r e l a t i o n s w e a c c u m u l a t e a p r o d u c t o f t h e f a c t o r s o f t h e r i g h t
h a n d s i d e o f ( 9 . 2 0 ) . W e m a k e a h a s h t a b l e c o n t a i n i n g a n e n t r y f o r e a c h n o r m a l p r i m e p a n d
( r
1
: r
2
) 2 R ( p ) w e e n c o u n t e r . E a c h e n t r y c o n t a i n s t h e e x p o n e n t o f t h e c o r r e s p o n d i n g p r i m e
i d e a l i n t h e a c c u m u l a t e d p r o d u c t s o f a r : i f w e m e e t a n o r m a l p r i m e p
( r
1
: r
2
)
d i v i d i n g a f r e e
p r i m e o r F ( a ; b ) i n t h e n u m e r a t o r ( o r d e n o m i n a t o r ) o f <
1
>
Ot o t h e p o w e r x , w e a d d ( o r
s u b t r a c t ) x t o t h i s e x p o n e n t . I f w e e n c o u n t e r a s p e c i a l p r i m e p
( r
1
: r
2
)
, d i v i d i n g a f r e e p r i m e
p o r o n e o f t h e F ( a ; b ) , w e u s e P A R I t o c a l c u l a t e t h e v a l u a t i o n o f < p > O o r < a b > O J ,
r e s p e c t i v e l y , a t t h e i d e a l s o f p
( r
1
: r
2
)
w e c o m p u t e d e a r l i e r . A l s o f o r t h e s e s p e c i a l i d e a l s w e k e e p
t r a c k o f t h e e x p o n e n t o f t h e i d e a l i n t h e a c c u m u l a t e d p r o d u c t s o f a r . W e a l s o h a v e t o k e e p
t r a c k o f t h e e x p o n e n t o f J i n t h e a c c u m u l a t e d p r o d u c t . F o r e a c h i d e a l < a b > O J i n t h e
n u m e r a t o r o r d e n o m i n a t o r w e a d d o r s u b t r a c t 1 , r e s p e c t i v e l y . W h e n w e h a v e r e a d i n a l l f r e e
p r i m e s a n d r e l a t i o n s w e h a v e f a c t o r e d <
1
> O i n t o p r i m e i d e a l s a n d a p o w e r o f J .
N o w w e s t a r t t h e i t e r a t i v e a p p r o x i m a t i o n p r o c e s s i n w h i c h w e u s e a l a t t i c e b a s i s r e d u c t i o n
a l g o r i t h m ( L L L ) 1 2 ] . A s s u m e w e w a n t t o s i m p l i f y t h e n u m e r a t o r . T h e a l g o r i t h m s e l e c t s a n
i d e a l I = P
s
1
1
: : : P
s
k
k
d i v i d i n g t h e n u m e r a t o r o f O , w i t h s
r
> 0 f o r a l l r . N ( I ) s h o u l d
b e c h o s e n a s l a r g e a s c o m p u t a t i o n a l l y c o n v e n i e n t f o r t h i s r s t l a t t i c e b a s i s r e d u c t i o n . L e t
f a
1
; : : : ; a
d
g b e a n i n t e g r a l b a s e s o f O . W i t h h e l p o f P A R I w e c o n s t r u c t a b a s i s i n H e r m i t e
N o r m a l F o r m ( H N F ) 5 , x 4 . 7 . 2 ] e x p r e s s e d i n f a
1
; : : : ; a
d
g f o r e a c h p r i m e i d e a l P
l
o c c u r r i n g i n
-
8/13/2019 An Implementation of the Number Field Sieve
20/28
9 . E x t r a c t i n g t h e s q u a r e r o o t 1 8
I . P A R I u s e s t h e s e b a s e s t o c o n s t r u c t a b a s i s o f I , a l s o i n H N F e x p r e s s e d i n f a
1
; : : : ; a
d
g .
T h e n w e a p p l y a l a t t i c e b a s i s r e d u c t i o n t o t h e s e d b a s i s v e c t o r s o f I . W e n d a b a s i s o f
I c o n s i s t i n g o f ` s m a l l ' v e c t o r s . I n p r a c t i c e , w h e n u s i n g o n e o f t h e s e s m a l l v e c t o r s f o r o u r
a p p r o x i m a t i o n
j
, t h e n o r m o f t h e n u m e r a t o r o f <
j + 1
> O
i
w i l l d e c r e a s e b y a f a c t o r N ( I ) i n
c o m p a r i s o n w i t h t h e n o r m o f t h e n u m e r a t o r o f <
j
>
O. I n c o m p a r i s o n w i t h t h e n o r m o f t h e
d e n o m i n a t o r o f <
j
>
O, t h e n o r m o f t h e d e n o m i n a t o r o f <
j + 1
>
Ow i l l i n c r e a s e b y a f a c t o r
m u c h s m a l l e r t h a n N ( I ) .
W e a p p l y a s e c o n d l a t t i c e b a s i s r e d u c t i o n t o a s l i g h t m o d i c a t i o n o f t h e b a s i s w h i c h w e n d
a f t e r t h e r s t l a t t i c e b a s i s r e d u c t i o n , t o s e a r c h f o r a n e l e m e n t
j
i n
I, w h i c h s t i l l h a s t h e s a m e
e e c t o n t h e n o r m o f <
j + 1
> O , b u t y i e l d s s m a l l j
j + 1
(
l
) j f o r a l l l . L e t v
( 1 )
, v
( 2 )
; : : : ; v
( d )
b e
t h e r e d u c e d b a s i s a f t e r t h e r s t l a t t i c e b a s i s r e d u c t i o n , w h e r e v
( r )
=
P
d 1
k = 0
v
( r )
k
k
. W h i l e w e
r e a d i n t h e f r e e p r i m e s a n d r e l a t i o n s w e c a l c u l a t e a n a p p r o x i m a t i o n o f
1
(
l
) f o r 1 l d .
W e c h o o s e c s u c h t h a t
c
d
=
L
m a x
( N (
j
) )
1 = 2
N ( I ) ( D i s c ( f = c
d
) )
1 = 2
;
w h e r e D i s c ( g ) i n d i c a t e s t h e d i