You are on page 1of 27

19CSE331 Cryptography 3-0-0-3

Computer Arithmetic-
Modular Algebra

Lecture - 3
Modular algebra
•a & m integers: a > m
•express a as
•a = q  m + r  q - quotient & r- remainder
•r – ‘residue’ – obtained by dividing a by m
•residue r can represent a
•r called ‘a modulus m’ - expressed as 
•r ≡ a (mod m ) ← ‘≡’ signifies equality in modular sense
•r ← representation can be generalized and used for all
a  ℤ.
•Examples
•2 ≡ 14 (mod 12) ≡ 26 (mod 12) ≡ 38 (mod 12)
representation - visualized as arranging integers in circular
fashion as with a clock 2
-12
0
12 -11
-1
24 1
11 13
23 25
35

-1
-2

2
0
10

14
22

26
34

7
2
5
1
3
9
-
Integers
arranged to

28
32

16
20

4
8

-8
conform to
-4

29
31 17
19 5
7 30 -7
-5

congruence
18
6
-6
3
• 2 ≡ - 10 (mod 12) ←negative numbers
•  add positive / negative multiples of 12 (in general m) to number
& bring result within (0, 1, 2, 3, . . . ,11) range.
• – 22,-10, 2,14, 26, . same representation  2
• – 22, -10, 2, 14, 26, . ‘congruent modulo 12’
• – 23,-11,1,13, 25, .  ‘congruent modulo 12’
• Generalize: a, b, & c - 3 integers:
a (mod m) = b (mod m) = c (mod m)
a, b, & c – ‘congruent’

4
• congruence property expressed as
• a (mod m) ≡ b (mod m) ≡ c (mod m)
•  a - b, b - c, a – c divisible by m
• additional examples:
3 ≡ 18 (mod 15)
- 3 ≡ -18 (mod 15)
12 ≡ - 3 (mod 15)
7 ≡ 18 (mod 11)
4 ≡ - 18 (mod 11)

5
• set of integers {. . . -2m, -m, 0, m, 2m, . . }  same
representation – 0 – in ℤm
• set of integers {. . -2m+a, -m+a, a, m+a, 2m+a, . . . }  same
representation – a – in ℤm
• set – {. . -2m+a, -m+a, a, m+a, 2m+a, . . . } – is called ‘the
residue class [a]m’
• [3]13 = {. . . -23, -10, 3, 16, 29, . . }
• [0]13 = {. . . -26, -13, 0, 13, 26, . . . }
• smallest positive number of a residue class is present in the set
of least residues
• given integer c, identifying an a  ℤm such that
• a ≡ c (mod m)  ‘reducing c modulo m’

6
• Extend concepts of basic algebraic operations to ℤm
• add 25 & 47 with m = 7
• (25 + 47)(mod 7) ≡ 72 (mod 7) ≡ 2
• same can be obtained as
• (25(mod 7) + 47(mod 7))(mod 7) ≡ (4 + 5) (mod 7) ≡ 2
• Similarly (25 – 47)(mod 7) ≡ (-22) (mod 7) ≡ 6
• Alternatively
• (25 – 47)(mod 7) ≡ (25(mod 7) – 47(mod 7))(mod 7)
• ≡ (4 – 5) (mod 7) ≡ 6
• add two integers in ℤ7; reduce result modulo 7,
 result in ℤ7
See table for general addition of two numbers a and b (mod 7)7
Addition of a & b modulo 7
a
0 1 2 3 4 5 6
b 0 0 1 2 3 4 5 6
b 1 1 2 3 4 5 6 0
b 2 2 3 4 5 6 0 1
b 3 3 4 5 6 0 1 2
b 4 4 5 6 0 1 2 3
b 5 5 6 0 1 2 3 4
b 6 6 0 1 2 3 4 5
• modular addition / subtraction using of look-up table not practical
• Use relations
(a + b)(mod m) ≡ (a(mod m) + b(mod m))( mod m)
(a – b)(mod m) ≡ (a(mod m) – b(mod m))( mod m)
8
• Extend concept to modular multiplication
• (25  47)(mod 7) ≡ (25(mod 7)  47(mod 7))(mod 7)
• ≡ (4  5)(mod 7) ≡ 20(mod 7 ) ≡ 6
• same result obtained as
• (25  47)(mod7) ≡ 1175(mod7) ≡ 6
• multiply two integers in ℤ7 & reduce result modulo 7 
result in ℤ7
• Modular multiplication of a & b (mod 7) ?
•  use table 

9
Table for ‘mod 7’
multiplication a
0 1 2 3 4 5 6
b 0 0 0 0 0 0 0 0
b 1 0 1 2 3 4 5 6
b 2 0 2 4 6 1 3 5
b 3 0 3 6 2 5 1 4
b 4 0 4 1 5 2 6 3
b 5 0 5 3 1 6 4 2
b 6 0 6 5 4 3 2 1
• Modular multiplication using table is not practical
• Use relation
• (a b)(mod m) ≡ (a(mod m)  b(mod m))(mod m)
10
• Consider integers 3 & 4 in ℤ7
• (3 + 4)(mod 7) ≡ 0
• role of 4 in ℤ7 same as that of -3 in ℤ
• 4 ‘additive inverse’ of 3 in ℤ7 & vice versa
• Every element in ℤ7 has an additive inverse
•  a unique inverse ← also an element of ℤ7
• generalized version:
• For any integer a  ℤm, b  ℤm is the additive inverse
of
a if (a + b)(mod m) ≡ 0
•  a is the additive inverse of b
• Additive inverse - a unique element in ℤm
• (c - b)(mod m) ≡ (c + (-b))(mod m) ← use additive inverse
of b & do subtraction 11
• Extend concept of inverses to multiplicative inverses
• a & b  ℤm :
• b is multiplicative inverse of a if a  b ≡ 1(mod m)
• multiplicative inverse of a  designated a-1 (mod m)  ‘a inverse
(mod m)’
• role of a-1 in ℤm  same as reciprocal of a as a real number
• multiplication of c  ℤm by a-1 ← analogous to dividing c by a in
the set of real numbers
• When m is a small integer, use ‘table of multiplicative inverses’ for
modular algebra
All non-zero elements of ℤ & their respective inverses
7

a 1 2 3 4 5 6
a-1 1 4 5 2 3 6
Two facts 
1.Every integer in ℤ7 has a multiplicative inverse.
2.A given integer has one & only one multiplicative inverse
12
• Table  multiplication table for ℤ6
• 5 has an inverse which is 5 itself 5-1 = 5 A
0 1 2 3 4 5
b 0 0 0 0 0 0 0
• No multiplicative inverses for 2,3,&4 in 1 0 1 2 3 4 5
ℤ6 2 0 2 4 0 2 4
3 0 3 0 3 0 3
•  they have a common divisor with 6!
• With a, b  ℤm, a has multiplicative 4 0 4 2 0 4 2
5 0 5 4 3 2 1
inverse b iff gcd (a, m) =1

13
• Use multiplicative inverse to carry out equivalent of division in
ℤm
Example in ℤ7:
3/4  3  4-1
Use table of inverses
 4-1 ≡ 2 (mod 7)
3
 4  3 2 (mod 7)
≡ 6 (mod 7)

14
Similarly

4 1
3  4 3 (mod 7)  3-1 ≡ 5 (mod 7)
 4 5 (mod 7)
 6(mod 7)
•m is small?
• Use table of inverses & multiply by inverse of divisor
for ‘division’
•Not practical with values of m used in cryptography
•Use extended Euclidean algorithm Solve Diophantine
Equation
• get multiplicative inverse & do ‘division’
15
•Obtain 3407-1(mod 4363)
Solution:
•(Incidentally 3407 and 4363 are primes)
•Use extended Euclidean algorithm
•-1536  4363 + 1967  3407 = 1
Some Practice Questions: (Use EEA)

1)Compute 7-1(mod 19) = 11 mod 19


2)Determine gcd(81, 97) and inverse of 81 in Z97
= 6 mod 97
1)1234-1(mod 4321) = 309 mod 4321

19
Euler Ø (phi) function’ or ‘Euler Totient function

20
Additional
Exercises
1.Make a table showing all quadratic residues and non-residues
modulo p for p = 3, 5, 7, 13, 17, 19.

2.Find how many elements have multiplicative inverse to exist in


your birth year.

3.Can you write a computer program and list all the numbers that
have
multiplicative inverses to exist.
To
• explore…
Do you think any number which is large and
has additive and multiplicative inverses to
exist will produce a strong cipher or still there
are other properties which are required to
produce a strong cipher.
If so can you specify the additional
characteristics that are
required to produce a strong cipher

You might also like