# Lecture: Modular Arithmetic and Fast Powering

This lecture introces the concept of modular arithmetic and presents a fast algorithm to compute the power of a number modulo another number. Constructive algorithms, based on the extended Euclidean algorithm, to compute modular inverses and solve the Chinese Remainder problem is presented. Finally, a modular algorithm for integer multiplication is discussed.

### Background Material

• Equivalence relations.
• Division with quotient and remainder.
• Euclidean algorithm (and extended version)

### Motivation

• Simple substitution cyphers (see practice assignment)
• Determining that a number is prime without factoring it (Fermat's theorem)

### Topics

• Equivalence relations
• Equivalence modulo n
• Equivalence classes modulo n
• Modular arithmetic (Z_n)
1. definition of + and *
2. proof that it is well defined
• modular inverses
1. Examples
2. Condition for inverses to exist
3. Computing with the extended Euclidean algorithm
4. Computing with Fermat's theorem
5. The finite field Z_p
• Fermat's theorem and Euler's identity
• Fast algorithm for powering
1. repeated multiplication
2. binary powering
3. Analysis of binary powering
• Chinese Remainder Theorem (CRT)
1. Existence proof
2. Constructive proof using the Extended Euclidean algorithm

### Maple worksheets and programs and other resources

• mod.mw - Maple worksheet on modular arithmetic, fast powering, the CRT, and modular algorithms
• mod.ppt (mod.pdf)- slides on modular arithmetic

### Practice Assignment

• lab2.mw - Maple lab (practice problems) on modular arithmetic and the Ceasar and Affine cyphers.
• Exercises 1.15, 1.19, 1.20, 1.23, and 1.25 of (HPS).
Created: April 21, 2008 (revised Sept. 28, 2016) by jjohnson AT cs DOT drexel DOT edu