Beruflich Dokumente
Kultur Dokumente
To run the primality tests based on Fermat’s Little Theorem and later on
for cryptography, you need to compute
a^k mod n
for large values of k efficiently. A fast way to do this is the method of squaring.
The idea is that it is very easy to compute the series of numbers
(1) a, a^2, a^4 = (a^2)^2, a^8 = (((a^2)^2)^2), ... mod n
where you keep squaring and reducing mod n at each step. The numbers involved
never get bigger than n^2. You could do this by hand or on a very primitive calculator.
Then, to compute a^k mod n, you write k in binary
k = 2^r1 + 2^r2 + ... + 2^rj
so that
a^k = a^(2^r1) x a^(2^r2) x ... x a^(2^rj)
is a product of numbers in the series in (1). These numbers are all less than n and
you can easily compute their product mod n.
The number of steps needed to compute a^k mod n by this method is approximately log base 2 of k.
Ref. Silverman, p.105. So the time needed, which of course depends on the equipment used,
grows logarithmically in k.
1110111002
modulo 541. Of course, we could take the product in stages, reducing mod 541 to keep
the numbers small. In any case the answer is
��� ��� Mod[temp, 541]
���� �� 386
Of course, we could just use the built in function to get (or check)
��� ��� Mod5 ^ 476, 541
���� �� 386
1100001112
so we can compute 5^391 as (starting at the right of the binary this time)
��� ��� temp2 = 5 * 25 * 84 * 306 * 43
���� �� 138 159 000
whereas
powers.nb ��� 3