Skip to main content
Logo image

PreTeXt Sample Book: Abstract Algebra (SAMPLE ONLY)

Section 4.4 Large Powers of Integers

Computing large powers can be very time-consuming. Just as anyone can compute 22 or 28, everyone knows how to compute
221000000.
However, such numbers are so large that we do not want to attempt the calculations; moreover, past a certain point the computations would not be feasible even if we had every computer in the world at our disposal. Even writing down the decimal representation of a very large number may not be reasonable. It could be thousands or even millions of digits long. However, if we could compute something like 237398332(mod46389), we could very easily write the result down since it would be a number between 0 and 46,388. If we want to compute powers modulo n quickly and efficiently, we will have to be clever.
 1 
The results in this section are needed only in Chapter 2 (not really).
The first thing to notice is that any number a can be written as the sum of distinct powers of 2; that is, we can write
a=2k1+2k2++2kn,
where k1<k2<<kn. This is just the binary representation of a. For example, the binary representation of 57 is 111001, since we can write 57=20+23+24+25.
The laws of exponents still work in Zn; that is, if bax(modn) and cay(modn), then bcax+y(modn). We can compute a2k(modn) in k multiplications by computing
a20(modn)a21(modn)a2k(modn).
Each step involves squaring the answer obtained in the previous step, dividing by n, and taking the remainder.

Example 4.4.1. Repeated Squares.

We will compute 271321(mod481). Notice that
321=20+26+28;
hence, computing 271321(mod481) is the same as computing
27120+26+28271202712627128(mod481).
So it will suffice to compute 2712i(mod481) where i=0,6,8. It is very easy to see that
27121=73,441329(mod481).
We can square this result to obtain a value for 27122(mod481):
27122(27121)2(mod481)(329)2(mod481)108,241(mod481)16(mod481).
We are using the fact that (a2n)2a22na2n+1(modn). Continuing, we can calculate
27126419(mod481)
and
2712816(mod481).
Therefore,
27132127120+26+28(mod481)271202712627128(mod481)27141916(mod481)1,816,784(mod481)47(mod481).
The method of repeated squares will prove to be a very useful tool when we explore RSA cryptography. To encode and decode messages in a reasonable manner under this scheme, it is necessary to be able to quickly compute large powers of integers mod n.

Remark 4.4.2. Sage.

Sage support for cyclic groups is a little spotty — but we can still make effective use of Sage and perhaps this situation could change soon.