2
2
2
(CSPC-307)
Mathematics of Cryptography 3e
Modular Arithmetic, Congruence,
and Matrices
Dr Samayveer Singh
Assistant Professor
Department of Computer Science & Engineering
National Institute Technology Jalandhar, Punjab, India
[email protected]
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
1 INTEGER ARITHMETIC
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
1.1 Set of Integers
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
1.2 Binary Operations
In cryptography, we are interested in three binary
operations applied to the set of integers. A binary
operation takes two inputs and creates one output.
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
1.2 Continued
Example 1
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
1.3 Integer Division
a=q×n+r
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
1.3 Continued
Example 2
Assume that a = 255 and n = 11. We can find q = 23 and R = 2
using the division algorithm.
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
1.3 Continued
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
1.3 Continued
Example 3
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
1.3 Continued
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
1.4 Divisbility
If a is not zero and we let r = 0 in the division
relation, we get
a=q×n
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
1.4 Continued
Example 4
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
1.4 Continued
Properties
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
1.4 Continued
Example 5
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
1.4 Continued
Example 6
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
1.4 Continued
Note
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
1.4 Continued
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
1.4 Continued
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
1.4 Continued
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
1.4 Continued
Note
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
1.4 Continued
Example 7
Find the greatest common divisor of 2740 and 1760.
Solution
We have gcd (2740, 1760) = 20.
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
1.4 Continued
Example 8
Find the greatest common divisor of 25 and 60.
Solution
We have gcd (25, 65) = 5.
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
1.4 Continued
Extended Euclidean Algorithm
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
1.4 Continued
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
1.4 Continued
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
1.4 Continued
Example 9
Given a = 161 and b = 28, find gcd (a, b) and the values of
s and t.
Solution
We get gcd (161, 28) = 7, s = −1 and t = 6.
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
1.4 Continued
Example 10
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
1.4 Continued
Example 11
Given a = 0 and b = 45, find gcd (a, b) and the values of s
and t.
Solution
We get gcd (0, 45) = 45, s = 0, and t = 1.
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
1.4 Continued
Linear Diophantine Equation
Note
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
1.4 Continued
Linear Diophantine Equation
Note
Particular solution:
x0 = (c/d)s and y0 = (c/d)t
Note
General solutions:
x = x0 + k (b/d) and y = y0 − k(a/d)
where k is an integer
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
1.4 Continued
Example 12
Solution
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
1.4 Continued
Example 13
(0, 20), (1, 16), (2, 12), (3, 8), (4, 4), (5, 0).
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
2 MODULAR ARITHMETIC
The division relationship (a = q × n + r) discussed
in the previous section has two inputs (a and n)
and two outputs (q and r). In modular arithmetic,
we are interested in only one of the outputs, the
remainder r.
2.1 Modular Operator
2.2 Set of Residues
2.3 Congruence
2.4 Operations in Zn
2.5 Addition and Multiplication Tables
2.6 Different Sets
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
2.1 Modulo Operator
The modulo operator is shown as mod. The second
input (n) is called the modulus. The output r is called
the residue.
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
1.4 Continued
Example 14
Solution
a. Dividing 27 by 5 results in r = 2
b. Dividing 36 by 12 results in r = 0.
c. Dividing −18 by 14 results in r = −4. After adding the
modulus r = 10
d. Dividing −7 by 10 results in r = −7. After adding the
modulus to −7, r = 3.
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
2.2 Set of Residues
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
2.3 Congruence
To show that two integers are congruent, we use the
congruence operator ( ≡ ). For example, we write:
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
2.3 Continued
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
2.3 Continued
Residue Classes
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
2.3 Continued
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
2.3 Continued
Example 15
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
2.4 Operation in Zn
The three binary operations that we discussed for the
set Z can also be defined for the set Zn. The result
may need to be mapped to Zn using the mod operator.
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
2.4 Continued
Example 16
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
2.4 Continued
Example 17
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
2.4 Continued
Properties
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
2.4 Continued
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
2.4 Continued
Example 18
The following shows the application of the above
properties:
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
2.4 Continued
Example 19
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
2.4 Continued
Example 20
We have been told in arithmetic that the remainder of
an integer divided by 3 is the same as the remainder of
the sum of its decimal digits. We write an integer as the
sum of its digits multiplied by the powers of 10.
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
2.5 Inverses
When we are working in modular arithmetic, we often
need to find the inverse of a number relative to an
operation. We are normally looking for an additive
inverse (relative to an addition operation) or a
multiplicative inverse (relative to a multiplication
operation).
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
2.5 Continue
Additive Inverse
Note
Solution
The six pairs of additive inverses are (0, 0), (1, 9), (2, 8),
(3, 7), (4, 6), and (5, 5).
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
2.5 Continue
Multiplicative Inverse
In Zn, two numbers a and b are the multiplicative inverse
of each other if
Note
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
2.5 Continued
Example 22
Example 23
Example 24
We have seven pairs: (1, 1), (2, 6), (3, 4), (5, 9), (7, 8), (9,
9), and (10, 10).
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
2.5 Continued
Note
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
2.5 Continued
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
2.5 Continued
Example 25
Find the multiplicative inverse of 11 in Z26.
Solution
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
2.5 Continued
Example 26
Find the multiplicative inverse of 23 in Z100.
Solution
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
2.5 Continued
Example 27
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
2.6 Addition and Multiplication Tables
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
2.7 Different Sets
Note
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
2.8 Two More Sets
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
3 MATRICES
3.1 Definitions
3.2 Operations and Relations
3.3 Determinants
3.4 Residue Matrices
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
3.1 Definition
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
3.1 Continued
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
3.2 Operations and Relations
Example 28
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
3.2 Continued
Example 29
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
3.2 Continued
Example 30
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
3.2 Continued
Example 31
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
3.3 Determinant
The determinant of a square matrix A of size m ×
m denoted as det (A) is a scalar calculated
recursively as shown below:
Note
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
3.3 Continued
Example 33
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
3.4 Inverses
Note
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
3.5 Residue Matrices
Example 34
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
4 LINEAR CONGRUENCE
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
4.1 Single-Variable Linear Equations
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
4.1 Continued
Example 35
Solve the equation 10 x ≡ 2(mod 15).
Solution
First we find the gcd (10 and 15) = 5. Since 5 does not divide
2, we have no solution.
Example 36
Solve the equation 14 x ≡ 12 (mod 18).
Solution
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
4.1 Continued
Example 37
Solution
First we change the equation to the form ax ≡ b (mod n).
We add −4 (the additive inverse of 4) to both sides, which
give 3x ≡ 2 (mod 13). Because gcd (3, 13) = 1, the equation
has only one solution, which is x0 = (2 × 3−1) mod 13 = 18
mod 13 = 5. We can see that the answer satisfies the
original equation: 3 × 5 + 4 ≡ 6 (mod 13).
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.
4.2 Single-Variable Linear Equations
We can also solve a set of linear equations with
the same modulus if the matrix formed from the
coefficients of the variables is invertible.
Solution
Copyright © 2015 by McGraw Hill Education (India) Private Limited. All rights reserved.