Professional Documents
Culture Documents
Nguyn nh Thc
Group of Cryptography-Complexity,
Department of Knowledge Engineering
ndthuc@fit.hcmuns.edu.vn
3/5/2008
3/5/2008
a|a ; 1|a
a|b, b|c a|c
a|b, a|c a|(bx + cy)
a|b, b|a a = b
a|b (-a)|b, a|(-b), (-a)|(-b)
2
Theorem: a, b N, a > b
gcd(a,b) = gcd(b,a%b)
3/5/2008
Euclid algorithm
Input: a,b N, a > b 1
Output: gcd(a,b)
While (b>0) {
r = a/b;
a = b;
b = r;
Return a
3/5/2008
Euclid theorem
a, b N, a > b > 1. Set a = r0, b = r1, we
have:
gcd(a,b)=gcd(r0,r1)==gcd(rn-1,rn)
=gcd(rnqn+rn+1,rn)=gcd(rnqn,rn)=rn
3/5/2008
???
3/5/2008
3/5/2008
Theorem
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
3/5/2008
Theorem
x= pP pxp, y= pP pyp, x,y 2
Set x0=2x2,x1=x/x0 ; y0=2y2,y1=y/y0
gcd(x,y) = 2mim(x2,y2)gcd(x1,y1)
If y is odd, gcd(x,y) = gcd(x1,y)
If x is even and y is odd,
gcd(x,y)=gcd(x/2,y)
X y and x, y: odd,
gcd(x,y) = gcd(|x-y|/2,min(x,y))
3/5/2008
10
}//End-while
While (x>0){
While (x:even)
x=x/2
While (y:even)
y=y/2
t=|x-y|/2
If (xy)x=t Else y=t
}//End-while(x>0)
g = gy
Return g
3/5/2008
11
Theorem
Bezouts theorem: a,b N, a>b1;
we have:
x,y A: ax + by = gcd(a,b)
(a,b) = 1 x,y Z: ax + by = 1
12
Bezout algorithm
Input: ab
Output: d,x,y:d=gcd(a,b);ax+by=d
Algorithm
If (b=0) Then d = a; x = 1; y = 0
x2 = 1; x1 = 0; y2 = 0; y1 = 1
While (b>0) {
q=a/b; r=a-qb; x=x2-qx1; y=y2-qy1;
a=b; b=r; x2=x1; x1=x; y2=y1; y1=y;
}//end-while
d = a; x = x2; y = y2;
Return(d,x,y)
3/5/2008
13
x = x/2
y = y/2
g = 2g
While (u:even){
u=u/2
A=A/2; B=B/2
} Else A=(A+y)/2;
B=(B-x)/2
While (v:even){
v=v/2
If (C,D:even){
C=C/2; D=D/2
} Else C=(C+y)/2
D=(D-x)/2
If (uv){
u=u-v;A=A-C;B=B-D;
} Else {
v=v-u;C=C-A;D=D-B;
}//End-if-else
}//End-while(u>0)
}//End-while
u=x;v=y;A=1;B=0;C=0;;D=
1;
While (u>0) {
3/5/2008
If (A,B:even){
14