Professional Documents
Culture Documents
1
Practice
Modular Arithmetic
Short Introduction to Modular
Arithmetic
Why do we need to study modular arithmetic?
Important for asymmetric cryptography (RSA, elliptic curves,
etc.)
a a-1 ≡ 1 mod n
The inverse of 7 mod 9 is 4 since 7 x 4 ≡ 28 ≡ 1 mod 9.
5
Short Introduction to Modular
Arithmetic
Modular Arithmetic
There is the neutral element 0 with respect to addition, i.e., for all a
a + 0 ≡ a mod n
a + (-a) ≡ 0 mod n
a x 1 ≡ a mod n
7
Shift Cipher
Example for k = 7
Plaintext = ATTACK = 0, 19, 19, 0, 2, 10
Ciphertext = HAAHJR = 7, 0, 0, 7, 9, 17
Note that the letters ”wrap around” at the end of the alphabet, which
can mathematically be expressed as reduction modulo 26, e.g.,
19 + 7 = 26 ≡ 0 mod 26
8
Shift Cipher
9
Affine Cipher
10
Affine Cipher
11
Affine Cipher
Example
12
Short Introduction to Modular
Arithmetic
Modular Reduction
14
Short Introduction to Modular
Arithmetic
37 = 33 · 34 = 27 x 81 ≡ 6 x 4 mod 7
6 x 4 = 24 ≡ 3 mod 7
We can perform all these multiplications without a pocket
calculator, whereas mentally computing 37 = 2187 is a bit
challenging for most of us
For most algorithms it is advantageous to reduce
intermediate results as soon as possible.
15
Euler's totient function
φ(n) +0 +1 +2 +3 +4 +5 +6 +7 +8 +9
0+ 1 1 2 2 4 2 6 4 6
10+ 4 10 4 12 6 8 8 16 6 18
20+ 8 12 10 22 8 20 12 18 12 28
30+ 8 30 16 20 16 24 12 36 18 24
40+ 16 40 12 42 20 24 22 46 16 42
50+ 20 32 24 52 18 40 24 36 28 58
60+ 16 60 30 36 32 48 20 66 32 44
70+ 24 70 24 72 36 40 36 60 24 78
80+ 32 54 40 82 24 64 42 56 40 88
90+ 24 72 44 60 46 72 32 96 42 60
24 hour clock
calculator by modulus 12