12.1 A SHORT NUMBER-THEORETIC DIGRESSION [KOBLITZ, 1987]
Proposition 12.1:If a, k, n are positive integers, the complexity of modular exponentiation ak (modulo n) is O((log2 k)(log2 n)2).
Proof:The complexity of the multiplication two s-bit numbers in O(s2). If we write
![]()
each of the O(log2 k) powers a2j (modulo n) (j = 1, 2, …) can be computed in time O((log2 n)2).
![]()

Example 12.1
Evaluate y = 1311134 (modulo 39,979). First, the base-2 expansion of the exponent 134 is determined:
![]()
Next, Tj = 13112j (modulo 39,979) for 1 ≤ j ≤ 7 is computed by repeated squaring

Finally, y is expressed as a product

multiplying all of the terms {Tj} for which 2j appears in the base-2 expansion of 134 to obtain the value of y, y = 17,236.
Proposition 12.2: (Fermat's Little Theorem): If p is a prime number
12.2a ap = a (modulo p) for any integer, and
12.2b ap−1 = 1 (modulo p) if a is not divisible by p.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access