This preview shows pages 1–2. Sign up to view the full content.
Calculating Modular Exponents
Before we move on, one quick note about computation. Let's consider the amount of
work involved in exponentiation:
Consider calculating a
n1
(mod n), for a large value of n, perhaps with about 100 bits.
An iterative algorithm where you successively multiply values of a to an accumulator
variable won't suffice.
However, fast exponentiation, will work:
Power(base, exp, mod) {
if (exp == 0) return 1;
if (exp == 1) return base%mod;
if (exp%2 == 0) {
int temp = Power(base, exp/2, mod);
return (temp*temp)%mod;
}
return (base*Power(base, exp1, mod))%mod;
}
Basically, what we do here is cut our exponent down by half for each two iterations of
this algorithm. That means that we will do the operation of multiplying and modding only
about 200 times at most if n is 100 bits, as opposed to doing it 2
100
times which is far
worse.
For a quick analysis of the time complexity, multiplying two integers of n bits takes O(n
2
)
and we will do this O(n) times in fast exponentiation for a total time of O(n
3
) in the
number of bits of the numbers being multiplied. If n is the number itself, then the amount
of time is O(log
3
n).
Discrete Logs
A normal logarithm is defined as follows:
log
b
a = c
is equivalent to the exponential statement b
c
=a.
Basically, if you are given a and b, you have to determine which power to raise b to in
order to get the result a.
This is easy to do for real numbers, but difficult to do with integers in a field mod p.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview. Sign up
to
access the rest of the document.
 Summer '09

Click to edit the document details