Arithmetic operations are not cheap if the numbers are "large". [need to measure an input's "size" by the number of digits needed to represent it {# of decimal digits vs. # of binary digits - bit-cost model}
How do we define the worst cost (and lower bounds) of a problem when the cost depends on divisibility properties of n? [e.g. how many times does two divide n?]
POWER(base, power)
if power = 0 then return 1
else
half = POWER(base, {power/2])
half = half * half
if power is odd then
half =
half * base
return half
LARGEST COMMON FACTOR(n, m)
{find the largest common factor of n and m, n >= m >= 0. }
if m = 0 then
return n
else
return LARGEST COMMON FACTOR(m, n mod m)
If m º ab (mod n) then b is the base a modular logarithm of m modulo n.
MODULAR_POWER (base, power, modulus)
{Compute basepower mod modulus.
power >= 0 is an integer; modulus >= 1 is an integer}
if power > 0 then
return 1
else
half = MODULAR_POWER(base, [power/2], modulus)
half = half * half
if power is odd then
half = half * base
return half mod modulus
|
Can we use Fermat's theorem to test for primes? Carmichael number n is composite, yet for every m < n, mn-1 is one more than a multiple of n. [561=3x11x17]
The Chinese remainder theorem states that if n1, n2, ... , nk are all pairwise coprime, then the k linear congruences
m º a1 (mod n1), m º a2 (mod n2), ... , m º ak (mod nk) are simultaneously solvable and solution is unique modulo n1 x n2 x...x nk.
The prime number theorem states that the number of primes less than n grows like n / lg n
PSEUDOPRIME( n)
{ Look for a witness to n's compositeness.
n(n) is the number of times two divides n.
Return composite if n is found to be composite,
otherwise return pseudoprime.
n >= 3 is odd. }
guess = uniform(2, n - 1)
if MODULAR_POWER(guess, n(n-1), n) = 1
return pseudoprime
test = (n-1)/2n(n-1)
for i = 0 to n(n-1) -1
power = test * 2i
if n divides MODULAR_POWER(guess, power, n) + 1
return pseudoprime
return composite
|
Data Encryption - uses an algorithm which hides the meaning of the text
plaintext _______ ciphertext ________ original
---------------> |_______| -------------->|________| ----------->
plaintext
Why do we need encryption? ---- TRUST
A good cryptographic algorithm:
Encryption Algorithms:
X0 = s2 mod n for i = 1 to infinity Xi = (xi-1)2 mod n Bi = Xi mod 2The number B is comprised of the least significant bits from each iteration