Week 2
Week 2
Modular Arithmetic
where the first term is the quotient and the second the remainder.
2
Modular Arithmetic
m qn r (0 r n; q m / n )
– The remainder, r, is often referred to as a residue of m modulo n, and is the
smallest non-negative integer that differs from m by a multiple of n.
For example,
3
Modular Arithmetic
• Two integers, a and b are said to be congruent (denoted by) if:
that is, "a is congruent to b modulo m“
• The set of integers Zm = {0,1, ... m - 1} form the complete set of residues
modulo m -- there are only m different integers, mod m
• The operation a mod m denotes the residue of a, such that the residue is some
integer from 0 to m - 1. This operation is known as a modular reduction.
– Example:
10 2 (mod 4) because 4 | (10 2) 4
Modular Arithmetic
5
Modular Arithmetic
6
Modular Arithmetic
7
Modular Arithmetic
– Reducing each intermediate result modulo m yields the same result as doing
the entire calculation, and then reducing the result to modulo m:
This means that we can do modular arithmetic without worrying about whether
we will exceed some large arithmetic bound -- so such calculations can be
done on computers, even for large integer values.
8
Modular Arithmetic
9
Modular Arithmetic:
Exponentiation
• Recall that exponentiation is defined:
11
Modular Arithmetic: Division
13
Modular Arithmetic: Multiplicative Inverse
14
Finite, or Galois Fields
Notice anything?
(a b) mod 2 a XOR b
(a b) mod 2 a AND b
17
Modular Arithmetic
18
Zn*
19
Zn*
This theorem also plays an important role in the derivation of the famous RSA algorithm for
public-key cryptography .
Another application of this theorem will be in the speedup of the modular exponentiation
algorithm .
Multiplying the numbers in both sets (p and X) and taking the result
mod p yields
FERMAT’S THEOREM PROOF :
a * 2a *…* (p-1)a [1 * 2 * 3 *…* (p-1)] (mod p)
a p 1 ( p 1)!( p 1)!(mod p )
Thus on equating (p-1)! term from both the sides, since it is relatively
prime to p, result becomes,
a p 1 1(mod p )
28
Euler's Totient Function
• Here is what the Euler Totient Function values look like for
small values of n. (The dotted red line is the line f(n) = n - 1)
35
30
25
Totient(n)
20
15
10
0
1
11
13
15
17
19
21
23
25
27
29
n 30
Summary
31