Computer Security - Lecture-01 - 02 Mathematics For Security
Computer Security - Lecture-01 - 02 Mathematics For Security
Lecture: 01-02
Mathematics for Security
Books Recommended
Slide-2
Lecture-01-02: Mathematics for Security
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
Slide-3 IIT, JU
Why Need Mathematics in Cryptography?
❖ Modern cryptography is heavily based on some areas of mathematics,
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
Slide-5 IIT, JU
Binary Operations
❖ A binary operation takes two inputs (e.g. a and b) and creates one
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
Slide-7 IIT, JU
Integer Division
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
a=q×n+r
Where,
❖ a 🡪 dividend
❖ n 🡪 divisor
❖ q 🡪 quotient
❖ r 🡪 remainder
Note:
⮚ Division is not a binary operation, because it produces two output
instead of one (q and r). Instead, we can call it division relation.
Slide-8 IIT, JU
Integer Division
Example:
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
n r r=n+r
q q = q-1
Slide-11 IIT, JU
Divisibility
Division relation is: a=q×n+r
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
Where
a 🡪 dividend
n 🡪 divisor
q 🡪 quotient
r 🡪 remainder
a=q×n
We then say that
▪ n divides a
▪ or, n is a divisor of a
▪ or, a is divisible by n
Example:
Slide-13 IIT, JU
Properties of Divisibility
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
Slide-14 IIT, JU
GCD: Greatest Common Divisor
⮚ A positive integer can have more than one divisor. For example, the
integer 32 has six divisors: 1, 2, 4, 8, 16, 32.
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
Fact 1:
❑ The integer 1 has only one divisor, itself.
Fact 2:
❑ Any positive integer has at least two divisors, 1 and itself (but it can have
more).
Slide-16
GCD: Greatest Common Divisor
IIT, JU
GCD Using Euclidean Algorithm
⮚ Finding the GCD of two positive integers by listing all common
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
Fact 2: When both integer is positive, then gcd (a, b) = gcd (b, r),
where r is the remainder of dividing a by b (here the value
of first and second integer is changed until the second
integer becomes zero.
Example:
Gcd(36, 10) = gcd(10, 6) = gcd(6, 4) = gcd(4,2) = gcd(2, 0) = 2
Slide-17 IIT, JU
GCD Using Euclidean Algorithm
⮚ Figure below shows how we use Fact 1 and Fact 2 to calculate gcd (a, b)
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
Note:
⮚ When gcd (a, b) = 1, we say that a and b are relatively prime or they
are coprime.
Slide-18 IIT, JU
GCD Using Euclidean Algorithm
Example:
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
Solution:
Slide-19 IIT, JU
GCD Using Euclidean Algorithm
Example:
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
Solution:
We have gcd (25, 60) = 5.
Note:
⮚ The above example shows that it does not matter if the first number
is smaller than the second number. We immediately get our correct
ordering gcd(60, 25).
Slide-20 IIT, JU
Extended Euclidean Algorithm
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
Slide-21 IIT, JU
Extended Euclidean Algorithm
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
Note:
⮚ Figure shows that the extended Euclidean algorithm uses the same number
of steps as the Euclidean algorithm, however, in each step, we use three sets
of calculations and exchanges instead of one.
⮚ Here, three sets of variables are used: r’s, s’s and t’s.
Slide-22 IIT, JU
Extended Euclidean Algorithm
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
Slide-23 IIT, JU
Extended Euclidean Algorithm
Example:
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
Given a = 161 and b = 28, find gcd (a, b) and the values of s and t
such that gcd(a, b) = s × a + t × b.
Solution: r = r1 – q × r2 s = s1 – q × s2 t = t 1 – q × t 2
Slide-24 IIT, JU
Extended Euclidean Algorithm
Example:
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
Solution:
Slide-25 IIT, JU
Extended Euclidean Algorithm
Example:
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
Solution:
We get gcd (0, 45) = 45, s = 0, and t = 1.
Slide-26 IIT, JU
Modular Arithmetic
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
⮚ This division relation has two inputs (a and n) and two outputs (q
and r).
Slide-32 IIT, JU
Modular Arithmetic
⮚ The modulo operator is shown as mod. The second input (n) is
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
Slide-33 IIT, JU
Modular Arithmetic
Calculation of a mod
n: There are three cases:
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
Solution:
a. Dividing 27 by 5 results in r = 2. Therefore 27 mod 5 = 2
b. Dividing 36 by 12 results in r = 0. Therefore 36 mod 12 = 0
c. Dividing −18 by 14 results in r = −4. After adding the modulus
(14) with the result to make it non-negative, we have r = -4 + 14
= 10. Therefore -18 mod 14 = 10
d. Dividing −7 by 10 results in r = −7. After adding the modulus
(10) with the result to make it non-negative, we have r = -7 + 10
= 3. Therefore –7 mod 10 = 3
Slide-35 IIT, JU
Zn: Set of Residues
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
⮚ Figure below shows the set of residues Zn and three instances of the
set of residues Z2, Z6, Z11.
Slide-36 IIT, JU
Congruence
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
Slide-37 IIT, JU
Congruence
Figure below shows the idea of congruence.
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
Slide-38 IIT, JU
Modular Arithmetic
Residue Sets or Classes:
A residue class [a] or [a]n is the set of integers congruent modulo n. That
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
is, a residue class is the set of all integers such that x = a (mod n). For
example, if n = 5, we have five sets of residue classes [0], [1], [2], [3]
and [4] as shown below:
Note:
⮚ All the integers in the residue class [0] are reduced to 0 when we
apply the modulo 5 operation on them.
⮚ Similarly, all the integers in the residue class [1] are reduced to 1
when we apply the modulo 5 operation on them, and so on.
In each residue set or class, there is one element called the least residue.
For example, in set [0], [1], [2], [3] and [4], this element (least residue) is
1, 2, 3, and 4 respectively. The set of all of these least residues is written
as Z5 = {0, 1, 2, 3, 4}. In other words, the set Zn is the set of all least
residue modulo n.
Slide-39 IIT, JU
Modular Arithmetic: Inverse
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
❑ Multiplicative Inverse
❖ If the operation is multiplication, we are normally looking for
multiplicative inverse.
Slide-40 IIT, JU
Modular Arithmetic: Additive Inverse
⮚ In Zn, two numbers a and b are additive inverses of each other if
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
Example:
Find all additive inverse pairs in Z10.
Solution:
Slide-41 IIT, JU
Modular Arithmetic: Multiplicative Inverse
⮚ In Zn, two numbers a and b are the multiplicative inverse of each
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
other if
Example:
Find the multiplicative inverse of 8 in Z10.
Solution:
⮚ There is no multiplicative inverse of 8 in Z10 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.
Slide-42 IIT, JU
Modular Arithmetic: Multiplicative Inverse
Example:
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
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.
Example:
Find all multiplicative inverse pairs in Z11.
Solution:
We have seven pairs: (1, 1), (2, 6), (3, 4), (5, 9), (7, 8), (9, 5), and
(10, 10).
Slide-43 IIT, JU
Modular Arithmetic: Multiplicative Inverse
Multiplicative Inverse Using Extended Euclidean Algorithm:
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
Solution:
Slide-45 IIT, JU
Modular Arithmetic: Multiplicative Inverse
Example-2:
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
Solution:
Slide-46 IIT, JU
Modular Arithmetic: Multiplicative Inverse
Example-3:
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
Solution:
Slide-47 IIT, JU
Modular Arithmetic: Multiplicative Inverse
Multiplicative Inverse Using Fermat’s Little Theorem:
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
Example:
Find the multiplicative inverse of 8 in Z17 using Fermat’s Little
Theorem.
Solution:
Since, the modulus 17 is a prime, so according to Fermat’s Little theorem,
Slide-48 IIT, JU
Set of Additive and Multiplicative Inverse
Set of Additive Inverse Zn :
⮚ Zn is a set that contains all integers from 0 to n-1.
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
⮚ On the other hand, Each member of Zn* has a multiplicative inverse, but only
some members of Zn* have an additive inverse.
Slide-49 IIT, JU
Set of Additive and Multiplicative Inverse
Finding the number of elements in Zn :
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
Slide-50 IIT, JU
Set of Additive and Multiplicative Inverse
Example-1:
Find the number of elements in Z13* using Euler’s Phi-Function.
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
Solution:
Since 13 is a prime, so according to the second rule,
Φ(13)=(13-1)=12
Example-2:
Find the number of elements in Z10* using Euler’s Phi-Function.
Solution:
Since 10 is not a prime, so according to the third rule,
Solution:
Since 49 is not a prime and it can not be factored as the product of two
relatively primes, so according to the fourth rule,
Slide-53 IIT, JU
Set of Additive and Multiplicative Inverse
Two More Sets: Zp and Zp* :
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
⮚ Cryptography often uses two more sets: Zp and Zp*. The modulus
in these two sets is a prime number.
Slide-55 IIT, JU
Matrices
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
Example of Matrices:
⮚ Row matrix:
If a matrix has only one row (l), then it is called a row matrix.
⮚ Column matrix:
If a matrix has only one column (m), then it is called a
column matrix.
Slide-57 IIT, JU
Matrices
Example of Matrices:
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
⮚ Square matrix:
If a matrix has same number of rows and columns (l = m), then it is called
a square matrix. In a square matrix, the elements a11, a22, ….. ,amm make
the main diagonal.
⮚ Additive Identity matrix:
It is a kind of matrix with all rows and columns set to 0’s. It is denoted as
O.
⮚ Identity matrix:
It is a kind of square matrix with 1’s on the main diagonal and 0’s
elsewhere. It is denoted as I.
Slide-58 IIT, JU
Matrices
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
Equality:
Two matrices are equal if they have the same number of rows and columns and
the corresponding elements are equal. In other words, A = B if we have aij = Bij
for all i’s and j’s.
Slide-59 IIT, JU
Matrices
Two matrices can be added if they have the same number of rows and columns.
The resulting matrix has also the same number of rows and columns, e.g. A + B =
C.
Example:
Multiplication:
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
Two matrices can be multiplied if the number of columns of the first matrix is the
same as the number of rows of the second matrix. If A is an l×m matrix and B is
an m×p matrix, then their product is a matrix C of size l×p.
Slide-62 IIT, JU
Matrices
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
Scalar Multiplication:
We can multiply a matrix by a number (called a scalar). If A is an l×m matrix and
x is a scalar, then C = xA is a matrix of size l×m.
A matrix which is formed by turning all the rows of a given matrix into
columns and vice-versa is called the transpose of the original matrix. The
transpose of matrix A is written AT.
Slide-64 IIT, JU
Matrices
Determinant
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
Slide-66 IIT, JU
Matrices
Example:
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
Slide-67 IIT, JU
Matrices
More Example
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
Slide-68 IIT, JU
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
Slide-69
Matrices
Cofactor Matrix of a Given Matrix
IIT, JU
Matrices
Adjoint of a Given Matrix
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
Slide-70 IIT, JU
Matrices
Inverse of Matrix
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
Slide-71 IIT, JU
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
Slide-72
Examples
Matrices
IIT, JU
Matrices
Determining the Inverse of Matrix
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
Example-1:
Slide-73 IIT, JU
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
Slide-74
Matrices
Example-2:
When A is a 2×2 Matrix:
IIT, JU
Matrices
When A is an m×m Matrix:
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
To find the inverse of an m×m matrix, follow the steps given below:
Slide-75 IIT, JU
Matrices
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
Solution:
The adjoint of A is :
The determinant of A is :
The inverse of A is :
Slide-76 IIT, JU
Matrices
Additive & Multiplicative Inverse of Matrix
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
Additive Inverse of a
Matrix:
The additive inverse of a matrix A is another matrix B such that A + B = 0. In
other words, we have aij = - bij for all values of i and j. Normally the additive
inverse of A is denoted by –A.
Slide-77 IIT, JU
Matrices
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
Multiplicative Inverse of a
Matrix:
The multiplicative inverse of a square matrix A is another square matrix B
such that A × B = B × A = I. Normally the multiplicative inverse of A is
denoted by A-1.
The multiplicative inverse exists only if the det(A) has a multiplicative inverse
in the corresponding set.
Slide-78 IIT, JU
Matrices
Residue Matrices
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
Example:
Slide-79 IIT, JU
Linear Congruence
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
Slide-80 IIT, JU
Linear Congruence
Single-Variable Linear Equations
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
Slide-81 IIT, JU
Linear Congruence
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
Slide-82 IIT, JU
Linear Congruence
Example:
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
Slide-83 IIT, JU
Linear Congruence
Example:
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
⮚ Because gcd (3, 13) = 1, the equation has only one solution,
which is:
x0 = (2 × 3−1) mod 13 = (2×9) mod 13 = 18 mod 13 = 5.
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.
To solve, we make three matrices:
⮚ The first is the square matrix made
Figure : Set of linear equations
from the coefficients of the variables.
Slide-86 IIT, JU
Linear Congruence
Example:
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
Solution
Slide-87 IIT, JU
Linear Congruence
Prepared by: K M Akkas Ali, Associate Professor, IIT, Jahangirnagar University, Dhaka
The result is
x ≡ 15 (mod 16)
y ≡ 4 (mod 16)
z ≡ 14 (mod 16)
Slide-88 IIT, JU