

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


So far, we have studied encryption functions that are constructed from addition and multiplication mod m. These encryption functions, are, however, not secure enough to use today. Among the encryption functions in use today, two of the most popular ones are based on taking the power of an element in Zm. In this section, we study a fast algorithm for finding a power mod m. We will not pursue the encryption functions based on exponentiation any further in this course, though. These are taught in more detail in the cryptography courses: CSci 162 (undergraduate Cryptography), CSci 284 (graduate introductory Cryptography) and CSci 381 (graduate Advanced Cryptography).
Consider how one might compute xk^ mod m for large values of x, k and m. If one actually performed k − 1 multiplications: x × x × ... × x, that could be a large number of multiplications. On the other hand, one might use the square-and-multiply rule which is considerably more efficient.
Let’s consider an example with small enough numbers to compute results by hand: 513 mod 17.
513 mod 17 = ((5^2 )^2 )^2 × (5^2 )^2 × 5
which involves only 5 multiplications instead of 12. Or another example:
515 mod 17 = ((5^2 )^2 )^2 × (5^2 )^2 × 52 × 5
which involves 6 multiplications.
This can be formalized as follows:
exponentiation(x, b, m) /* xb^ mod m*/
z := 1
/bi = ith^ bit in binary representation of b/
for i = l − 1 downto 0
z := z^2 mod n
if bi = 1 z := z × x mod n
endfor
return(z)
Example: 551 mod 7.
1
CSCI 124 and CSCI 297/Vora/GWU 2
i bi zf irst zsecond 5 1 1 5 4 1 25 mod 7 = 4 20 mod 7 = 6 3 0 1 1 2 0 1 1 1 1 1 5 0 1 4 6
Example: 729 mod 11
29 = 11101
i bi zf irst zsecond 4 1 1 7 3 1 5 2 2 1 4 6 1 0 3 3 0 1 9 8
Why do we believe this algorithm works? Suppose you wish to determine xn^ mod m.
You first express n in binary form. Let the binary expression for n be: bk− 1 bk− 2 ...b 0 where n is of length k bits. Then, n =
∑k− 1 i=0 bi^2 i. Hence,
xn^ = x(
k∏− 1
i=
xbi^2 i = xbk−^12 k−^1 × xbk−^22 k−^2 × ... × xb^020
where Π represents the product, as ∑^ represents the sum. The above expression is:
xn^ =
bi=
x^2 i
as the terms with bi = 0 reduce to the number 1.
The algorithm introduces a factor of x every time the bit bi is 1. Additionally, at each step, the algorithm squares the number. If one follows a single value of x after is introduced into the loop, it gets squared as many times as there are i loops left: ((((x)^2 )^2 )^2 )^2 ....)^2
If the x value is introduced in the loop for i = i 0 , it is squared i 0 times, and hence the factor it introduces into the final computed value is x^2 i^0. The final computed value is the product of all these values, hence it is the value desired. It will be easier to understand if one sees an example.
Example 1 39215 mod 121
Hence,
39215 = 391 ×^27 × 391 ×^26 × 390 ×^25 × 391 ×^24 × 390 ×^23 × 391 ×^22 × 391 ×^21 × 391 ×^20 = 3927 × 3926 × 3924 × 3922 × 3921 × 3920