Title: 1. Analysis
1?????-Introduction
1. Analysis 2. Basic arithmetic 3. Modular
arithmetic 4. GCD 5. Primality testing 6.
Cryptography
2Algorithm
1. Analysis
- Algorithma specified set of simple
- instructions to be
followed to - solve a problem.
- require how much in the way of
- resourecestime or space.
- ????algorithm??useful.
3Analysis
1. Analysis
- Note that
- 1. Input size
- 2. the number of basic computer steps
4Fibonacci
1. Analysis
Fibonacci number 0, 1, 1, 2, 3, 5, 8
Rule
5Fibonacci
1. Analysis
Exponential function fib1(n) if n0 return
0 if n1 return 1 return fib1(n-1) fib1(n-2)
polynomial function fib2(n) if n0 return 0
create an array f0n f00, f11 for
i2n fifi-1fi-2 return fn
T(n)T(n-1)T(n-2)3
T(n) n-1
T(n) ?Fn
6Fibonacci
1. Analysis
polynomial
T(n) O(logn)
4??8??
??2?2matrix??
7Fibonacci
1. Analysis
T(n) O(logn)
8Fibonacci
1. Analysis
???
9Big-O
1. Analysis
- DefT(N)O(f(N))
- if there are positive constant c and
n0 - such that T(N) cf(N) when N n0
- ?T(N)1000N, f(N)N2 n010 c100
- 1000N cN2 ?1000NO(N2)
10Big-O
1. Analysis
11Big-O
1. Analysis
???
12????function????
1. Analysis
- 1. ??function
- 2.
-
-
- ?? error
131. Analysis
NlogN
N logN
14????function????
1. Analysis
- 3. ??limit??f(N)?g(N)??
-
-
-
- ????NlogN?N1.5
152. Basic arithmetic
Addition
Inputx and y are each n bits long
bit complexity O(n)
162. Basic arithmetic
Multiplication
13 11 x 1101 and y 1011.
If x and y are both n bits, then there are n
intermediate rows, with lengths of up to 2n bits.
bit complexity O(n2)
172. Basic arithmetic
Multiplication
Khwarizmis method
13 11
??
bit complexity O(n2)
(??n)
182. Basic arithmetic
Multiplication
Karatsubas method
A 2n/2A1 A0
B 2n/2B1 B0
AB 2nA1B1 2n/2(A0B1 A1B0) A0B0
(2n 2n/2) A1B1 2n/2(A1-
A0)(B0- B1) (2n 1)A0B0
? T(n) ? 3T(n/2) cn ? T(n) ?
3cnlog23
bit complexity O(n1.585)
Schonhage-Strassens method (based on FFT)
bit complexity O(nlognloglogn)
192. Basic arithmetic
Division
x yq r and r lt y.
?Division of a 2n-bit integer by an n-bit integer
can be performed using O(n2) bit operations
?There is an algorithm to find the quotient q
x/y, when the 2n-bit integer x is divided
by the integer y having no more than n bits,
using O(M(n)), where M(n) is the number of
bit operations needed to multiply two n-bit
integers.
bit complexity O(nlognloglogn)
203. Modular arithmetic
x y (mod N) ?? N divides (x - y).
213. Modular arithmetic
223. Modular arithmetic
Modular addition
xy mod N
Since x and y are each in the range 0 to N - 1,
their sum is between 0 and 2(N - 1). If the
sum exceeds N - 1, we merely need to subtract off
N to bring it back into the required range. The
overall computation therefore consists of an
addition, and possibly a subtraction, of numbers
that never exceed 2N. Its running time is linear
in the sizes of these numbers, in other words
O(n), where n log N is the size of N
233. Modular arithmetic
Modular multiplication
x.y mod N
The product can be as large as (N - 1)2, but this
is still at most 2n bits long since log(N - 1)2
2 log(N - 1) 2n. To reduce the answer modulo N,
we compute the remainder upon dividing it by N,
using our quadratic-time division algorithm.
Multiplication thus remains a quadratic operation.
O(n2)
243. Modular arithmetic
Modular exponentiation
xy mod N
O(y) modular multiplications
is clearly exponential in the size of y
O(logy) modular multiplications
bit complexity O(n3)
253. Modular arithmetic
Modular exponentiation
Square and multiply
3723 mod 55 53
3710111 ((((((((371)2)370)2)371)2)371)2)371)
mod 55
(..((371)2mod 55)370)2mod 55)371mod 55 )2mod 55
)371mod 55)2mod 55)371) mod 55 53
265. Primality testing
But, 341 11 31 is not prime, and yet 2340 1
mod 341
(a2)
275. Primality testing
Carmichael Numbers
285. Primality testing
Lemma If aN-1 1 mod N for some a relatively
prime to N, then it must hold for at least half
the choices of a lt N.
If N is prime, then aN-1 1 mod N for all a lt
N. If N is not prime, then aN-1 1 mod N for at
most half the values of a lt N.
295. Primality testing
Pr(Algorithm 1.8 returns yes when N is not prime)
1/2k
305. Primality testing
Given a number N, prove that N is a prime.
Sieve of Eratosthenes Miller 1975 (using Riemann
hypothesis) Adleman, Pomerance and Rumely
1983 Agrawal, Kayal and Saxena 2002 Lenstra
and Pomerance 2003
316. Cryptography
RSA
1. ??? 2 ???? p ? q (??100??),? N p q 2.
???Ø(N)(p-1)(q-1),?? 1 ??Ø(N)??? e
Ø(N)?Eulers Totient??,????N????? 3. (e,N)
????????? ???? C Me mod N 4.
??? 1 ?? d,?? e d mod Ø(N) 1 5. d
?????????(???????????) ???? M
Cd mod N
? RSA???????????????? ? ?????N?????P?Q???,?????
326. Cryptography
- 1. ??? p5 , q11 ?? N p q 5 x 11 55
- 2. ???? 1 ?? ( p-1 ) x ( q-1 ) ( 5-1 )( 11-1
) - 4 x 10 40
- ??? e7
- 3. ( e, N) (7,55) ?????????
- 4. ??? 1 ?? d7 ??????,
- ?? e d ? 1 mod 40 ( 7 x 23 ? 1 mod 40 )
- ??? M 53
- ?? C Me mod N 537 mod 55 37
- ?? M Cd mod N 3723 mod 55 53