Cryptography and Network Security Behrouz ch02 Slides
Cryptography and Network Security Behrouz ch02 Slides
Mathematics of
Cryptography
Part I: Modular Arithmetic, Congruence,
and Matrices
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
2.1
Objectives
In integer arithmetic,
we use a set and a few operations.
You are familiar with this set and
the corresponding operations,
but they are reviewed here to create
a background for modular arithmetic.
2.4
2.1.1 Set of Integers
2.5
2.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.
Figure 2.2 Three binary operations for the set of integers
2.6
2.1.2 Binary Operations
The following shows the results of
the three binary operations on two integers.
Because each input can be
either positive or negative,
we can have four cases for each operation.
Example 2.1
2.7
2.1.3 Integer Division
2.8
2.1.3 Integer Division
Example 2.2
Assume that a = 255 and n = 11.
We can find q = 23 and r = 2 using the division algorithm.
Figure 2.3 Example 2.2, finding the quotient and the remainder
2.9
2.1.3 Integer Division
2.10
2.1.3 Integer Division
Example 2.3
When we use a computer or a calculator,
r and q are negative when a is negative.
How can we apply the restriction
that r needs to be positive?
The solution is simple, we decrement the value of q by 1
and we add the value of n to r to make it positive.
2.11
2.1.3 Integer Division
2.12
2.1.4 Divisibility
2.13
2.1.4 Divisibility
Example 2.4
a. The integer 4 divides the integer 32
because 32 = 8 × 4.
We show this as
2.14
2.1.4 Divisibility
Properties
2.15
2.1.4 Divisibility
Example 2.5
2.16
2.1.4 Divisibility
Example 2.6
2.17
2.1.4 Divisibility
Note
Fact 1: The integer 1 has only one divisor, itself.
2.18
2.1.4 Divisibility
2.19
2.1.4 Divisibility
Euclidean Algorithm
Solution
We have gcd (2740, 1760) = 20.
2.22
2.1.4 Divisibility
Example 2.8
Find the greatest common divisor of 25 and 60.
Solution
We have gcd (25, 65) = 5.
2.23
2.1.4 Divisibility
Extended Euclidean Algorithm
2.24
2.1.4 Divisibility
2.25
2.1.4 Divisibility
Figure 2.8.b Extended Euclidean algorithm, part b
2.26
2.1.4 Divisibility
Example 2.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.
Example 2.10
Given a = 17 and b = 0,
find gcd (a, b) and the values of s and t.
Solution
We get gcd (17, 0) = 17, s = 1, and t = 0.
2.28
2.1.4 Divisibility
Example 2.11
Solution
We get gcd (0, 45) = 45, s = 0, and t = 1.
2.29
2.1.4 Divisibility
General solutions:
x = x0 + k (b/d) and y = y0 − k(a/d)
where k is an integer
2.32
2.1.4 Divisibility
Example 2.12
Solution
2.33
2.1.4 Divisibility
Example 2.13
Imagine we want to cash a $100 check
and get some $20 and some $5 bills.
We have many choices, which we can find by solving
the corresponding Diophantine equation 20x + 5y = 100.
Since d = gcd (20, 5) = 5 and 5 | 100,
the equation has an infinite number of solutions,
but only a few of them are acceptable in this case.
The general solutions with x and y nonnegative are
(0, 20), (1, 16), (2, 12), (3, 8), (4, 4), (5, 0).
2.34
2.2 MODULAR ARITHMETIC
2.35
2.2.1 Modulo Operator
2.36
2.2.1 Modulo Operator
Example 2.14
Find the result of the following operations:
a. 27 mod 5 b. 36 mod 12
c. −18 mod 14 d. −7 mod 10
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 to r = 10.
d. Dividing −7 by 10 results in r = −7.
After adding the modulus to −7, r = 3.
2.37
2.2.2 Set of Residues
2.38
2.2.3 Congruence
2.39
2.2.3 Congruence
2.40
2.2.3 Congruence
Residue Classes
2.41
2.2.3 Congruence
2.42
2.2.3 Congruence
Example 2.15
2.43
2.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.
Figure 2.13 Binary operations in Zn
2.44
2.2.4 Operation in Zn
Example 2.16
Solution
2.45
2.2.4 Operation in Zn
Example 2.17
Perform the following operations
(the inputs come from either Z or Zn):
a. Add 17 to 27 in Z14.
b. Subtract 43 from 12 in Z13.
c. Multiply 123 by −10 in Z19.
Solution
2.46
2.2.4 Operation in Zn
Properties
2.47
2.2.4 Operation in Zn
Figure 2.14 Properties of mode operator
2.48
2.2.4 Operation in Zn
Example 2.18
2.49
2.2.4 Operation in Zn
Example 2.19
In arithmetic,
we often need to find the remainder of powers of 10
when divided by an integer.
2.50
2.2.4 Operation in Zn
Example 2.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.
2.51
2.2.5 Inverses
2.52
2.2.5 Inverses
Additive Inverse
In Zn, two numbers a and b are
additive inverses of each other if
In modular arithmetic,
each integer has an additive inverse.
The sum of an integer and its additive inverse
is congruent to 0 modulo n.
2.53
2.2.5 Inverses
Example 2.21
Find all additive inverse pairs in Z10.
Solution
2.54
2.2.5 Inverses
Multiplicative Inverse
In modular arithmetic,
an integer may or may not have a multiplicative inverse.
When it does,
the product of the integer and its multiplicative inverse
is congruent to 1 modulo n.
2.55
2.2.5 Inverses
Example 2.22
Find the multiplicative inverse of 8 in Z10.
Solution
There is no multiplicative inverse because gcd (10, 8) = 2 ≠ 1.
In other words, we cannot find any number between 0 and 9
such that when multiplied by 8, the result is congruent to 1.
Example 2.23
Find all multiplicative inverses in Z10.
Solution
There are only three pairs: (1, 1), (3, 7) and (9, 9).
The numbers 0, 2, 4, 5, 6, and 8
do not have a multiplicative inverse.
2.56
2.2.5 Inverses
Example 2.24
Find all multiplicative inverse pairs in Z11.
Solution
2.57
2.2.5 Inverses
2.58
2.2.5 Inverses
Figure 2.15 Using extended Euclidean algorithm
to find multiplicative inverse
2.59
2.2.5 Inverses
Example 2.25
Find the multiplicative inverse of 11 in Z26.
Solution
Example 2.26
Find the multiplicative inverse of 23 in Z100.
Solution
Example 2.27
Find the inverse of 12 in Z26.
Solution
2.62
2.2.6 Addition and
Multiplication Tables
2.63
2.2.7 Different Sets
We need to use Zn
when additive inverses are needed;
we need to use Zn*
when multiplicative inverses are needed.
2.64
2.2.8 Two More Sets
2.65
2.3 MATRICES
2.66
2.3.1 Definition
2.67
2.3.1 Definition
2.68
2.3.2 Operations and Relations
Equality, Addition and Subtraction.
Example 2.28
Figure 2.20 shows an example of
addition and subtraction.
Figure 2.20 Addition and subtraction of matrices
2.69
2.3.2 Operations and Relations
Multiplication.
Example 2. 29
Figure 2.21 shows the product of
a row matrix (1 × 3) by a column matrix (3 × 1).
The result is a matrix of size 1 × 1.
2.70
2.3.2 Operations and Relations
Example 2. 30
2.71
2.3.2 Operations and Relations
Scalar Multiplication.
Example 2. 31
2.72
2.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:
2.73
2.3.3 Determinant
Example 2. 32
2.74
2.3.3 Determinant
Example 2. 33
2.75
2.3.4 Inverses
Additive inverse : A + B = 0.
Multiplicative inverse : A × B = B × A = I.
2.76
2.3.5 Residue Matrices
2.77
2.3.5 Residue Matrices
Example 2. 34
Scalar Multiplication.
2.78
2.4 LINEAR CONGRUENCE
Cryptography often involves
solving an equation or
a set of equations of one or more variables
with coefficient in Zn.
This section shows how to solve equations
when the power of each variable is 1
(linear equation).
2.79
2.4.1 Single-Variable Linear Equations
Equations of the form ax ≡ b (mod n ) might have
no solution or a limited number of solutions.
Example 2.36
Solve the equation 14 x ≡ 12 (mod 18).
Solution
2.81
2.4.1 Single-Variable Linear Equations
Example 2.37
Solve the equation 3x + 4 ≡ 6 (mod 13).
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).
2.82
2.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.
Figure 2.27 Set of linear equations
2.83
2.4.2 Single-Variable Linear Equations
Example 2.38
Solve the set of following three equations:
Solution
The result is
x ≡ 15 (mod 16), y ≡ 4 (mod 16), and z ≡ 14 (mod 16).
We can check the answer
by inserting these values into the equations.
2.84