Unit-1 - Part-II
Unit-1 - Part-II
Mathematics of Cryptography
Set of Integers: The set of Integers, denoted by z, contains all integral numbers (with no
fraction) from negative infinity to positive infinity.
Z= {………,-4-3,-2,-1,0,1,2,3,4………}
Binary Operations: A Binary operation takes two inputs and creates one output. Three
common binary operations defined for integers are addition, subtraction and
multiplication.
Z= {………,-4-3,-2,-1,0,1,2,3,4………}
a b
+-x
c
Z= {………,-4-3,-2,-1,0,1,2,3,4………}
Examples:
Add: 5+9=14 (-5)+9=4 5+(-9)=-4
Subtract: 5-9=-4 (-5)-9=14 5-(-9)=14
Multiply: 5x9=45 (-5)x9=-45 5x(-9)=45
Two Restrictions:
• First, we require that the divisor be a positive integer (n > 0).
• Second, we require that the remainder be a non-negative integer ( r > 0 ).
Integer Division
32
The number 8 does not divide the number 42 because 42 = 5 x 8 + 2. There is a remainder,
the number 2, in the equation.
We show this as 8 + 42. Examples:
1) Since 3 | 15 and 15 | 45, according to third property, 3 | 45
2) Since 3 | 15 and 3 | 9, according to the fourth property, 3 |(15 x 2 + 9 x 4), which
means 3 | 66.
Euclidean Algorithm:
Euclidean algorithm is used to finding the greatest common divisor (gcd) of two
positive integers. The Euclidean algorithm is based on the following two facts
Fact 1: gcd ( a, 0 ) = a
Fact 2: gcd ( a, b ) = gcd ( b , r ), where r is the remainder of dividing a
by b
When gcd ( a, b ) = 1, we say that a and b are relatively prime.
The Extended Euclidean Algorithm can calculate the gcd ( a, b) and at the same time
calculate the value if s and t.
Example: Given a = 161 and b = 28, Find gcd (a,b) and the values of s and t.
Solution:
r = r1 – q x r2 , t = t1 – q x t2 , s = s1 – q x s2 , We use a table to follow the algorithm.
3x + 2y = 5 2
Modular Arithmetic
The division relationship ( a = q x n + r ) has two inputs ( a and n ) and two outputs ( q
and r ). In modular arithmetic, we are focused in only one of the outputs, the remainder r.
Modulo Operator:
Modulo operator is shown as mod.
The second input (n) is called the modulus.
The output r is called the residue.
The below figure shows the division relation compared to the modulo operator
The modulo operator (mod) takes an integer (a) from the set Z and a positive modulus
(n). The operator creates a non-negative residue (r).
a mod n = r
Example
SET OF RESIDUES: Zn
The result of the modulo operation with modulus „n‟ is always an integer between 0 and
n-1. In other words (a mod n) is always a non-negative integer less than n
Modulus operation creates a set, that is called set of least residues modulo n or Z n
We have one set of Z(integers), but we have infinite instances of the set o residues Z n for
each n.
CONGRUENCE (≡)
If two numbers A and B have the property that their difference A-B is integrally
divisible by a number C (i.e., (A-B)/C is an integer), then A and B are said to be
"congruent modulo C." The number C is called the modulus, and the statement "A is
congruent to B (modulo C)" is written mathematically as
A ≡ B ( mod C)
This says that “ A is congruent to B modulo C”.
Example 2:
Assume, -8≡12(mod 10) 2≡12(mod 10) 12≡22(mod 10) 22≡32(mod 10)
Residue classes
A residue class [a] is the set of integers congruent modulo n. In other words it is the set of
Example 2
Perform the following operation:
a. Add 17 to 27 in Z14
(17+27) mod 14 = (44) mod 14 = 2
b. Subtract 34 from 12 in Z13
(12-34) mod 13 = (-22) mod 13 = - 9 = (-9+13) = 4
c. Multiply 123 by -10 in Z20
(123*(-10)) mod 20 = (-1230) mod 20 = -10 =(-10+20) = 10
Property 1:
(a+b) mod n= [ (a mod n )
+ (b mod n) ] mod n (4+5)
mod 2 = [ (4 mod 2) + ( 5
mod 2) ] mod 2
9 mod 2 = [0 + 1] mod 2
1 = 1
Property 2:
(a-b) mod n= [ (a mod n ) - (b mod n) ] mod n
(4 - 5) mod 2 = [ (4 mod 2) - ( 5 mod 2) ] mod 2
-1 mod 2 = [0 - 1] mod 2
-1 mod 2 = -1 mod 2
Property 3:
(axb) mod n= [ (a mod n ) x (b mod n) ] mod n (4 x 5) mod 2 = [ (4 mod 2) x ( 5 mod
2) ] mod 2
20 mod 2 = [0 x 1] mod 2
0 = 0 mod 2
0 = 0
Inverses
When we are working in modular arithmetic, we need to find inverse of a number
relative to an operation. There are two types of inverses are used modular arithmetic.
Additive inverse (relative to an addition operation).
Multiplicative inverse (relative to a multiplication operation).
It can be proved that „a‟ has a multiplicative inverse in Zn iff gcd(n,a)=1. (In this case „a‟
and n are said to relatively prime.
Example 1: Find multiplicative inverse of 8 in Z10.
Matrices
A matrix is a rectangular array of l x m elements; in which l is the number of rows and
m is the number of columns.
A matrix is normally denoted with an Uppercase Letter such as A. The element aij is
located in the ith row and jth column.
Multiplication
Examples:
Multiplication unit matrix with normal matrix gives the same matrix
AXI=IXA=A
DETERMINANT
If A is square matrix of mxm then determinant of A is det(A)
Where Aij is a matrix obtained from A by deleting the ith row and jth column.
Determinant is obtained for only square matrices
Det(2x2) matrix
MATRICES-Inverses
Additive Inverse
The additive inverse of the matrix A is another matrix B such that A+B=0. In other words
bij=-aij
Generally additive inverse is of A=-A Multiplicative Inverse:
The multiplicative Inverse of a square matrix A is a B such that A X B = I. Normally
Multiplicative inverse of A is defined by A-1
Note: Multiplicative inverse is defined for only square matrices
Residue Matrices
Solution:
Linear Congruence
Single variable Linear Equations:
Equations of the form ax ≡ b (mod n) might have no solution or a limited number of
solutions
Assume that the gcd(a,n) = d.
If d + b (d not divides b), there is no solution. If d | b (d divides b), there are d solutions.
If d | b, we use the following strategy to find the solutions:
Reduce the equation by dividing both sides of the equation (including the modulus) by d.
Multiply both sides of the reduced equation by the multiplicative inverse of „a‟ to find the
particular solution x0.
The General solutions are x = x0 + k ( n / d ) for k = 0, 1, 2, , (d-1). Congruence-Example
Example 1: Solve the equation
10 x = 2( mod 15).
Solution :-
Given Linear equation 10x≡ 2(mod 15) In basic form ax ≡ b(mod n)
a = 10 ; b = 2; n= 15
Now, find d = ?
d = gcd(a,n)= gcd (10,15)
= gcd (15,10) = gcd (10,5)
= gcd (5,0)
=5
check if d+b (d not divides b), then no solution 5+2 means „5‟ not divides „2‟, so, The
given equation has No solution.
Example 2: Solve the equation
14 x= 12 (mod 18) Solution :- Given Linear equation
14x ≡ 12(mod 18) In basic form ax ≡ b(mod n)
a = 14 ; b = 12; n= 18
d = gcd(a,n)= gcd (14,18) = gcd (18,14)
= gcd (14,4) = gcd (4,2)=gcd(2,0)=2 check, d b or d+ b
d|b→ 2 | 12 means “ 2 divides 12”, so the given equation have “2 solutions”.
Algebraic Structures
Cryptography requires set of integers and specific operations that are defined for those
sets. The combination of the set and the operations that are applied to the elements of the
set is called an algebraic structure.
Basics of Groups
A Group (G) is a set elements with a binary operation “ ” usually Addition or
multiplication that satisfies four properties(Axioms).
A Commutative Group, also called an abelian group, is a group in which the operator
satisfies the four properties for groups plus an extra property, commutativity.
Closure Property: if a and b are elements of G, then c = a b is also an element
of G.
Associatively Property: if a, b, and c are elements of “G, then ( a b ) c = a
( b c ).
Existence of Identity Property: For all a in G, there exists an element e, called
the identity element, such that e a=a e=a
Existence of Inverse Property: For each a in G, there exists an element a1, called the
1
inverse of a, such that = a1
Commutativity Property: For all a and b in G,
Example 1
The set of residue integers with the addition operator, G=< Zn , + >, is a commutative group
Example 2
The set Zn* with multiplication operator, G=<Zn*, x >, is also an abelian group. We can
perform multiplication and divisions on the elements. We an identity element as 1.
Finite Group: A group is called a finite group if the set has a finite number of elements;
otherwise, it is an infinite group.
Order of a Group: The order of group, |G|, is the number of elements in the group. If the
group is not finite, its order is infinite; if the group is finite, the order is finite.
Cyclic Subgroup: If a subgroup of a group can be generated using the power of an element,
the subgroup is called the cyclic subgroup.
The term power means repeatedly applying the group operation to the element:
an -> a.a.a.a a (n times)
Example: The group G=< Z3, + > contains cyclic subgroups for 0,1 and 2: If generated using
0:
00 mod 3 = 0, 01 mod 3 = 0, 02 mod 3 = 0. so, H1=<{0}, +>
If generated using 1:
10 mod 3 = 0, 11 mod 3 = 1, 12 mod 3 = (1+1) mod 3=2. so, H2=G If generated using 2:
20 mod 3 = 0, 21 mod 3 = 2, 22 mod 3 = (2+2) mod 3=1. so, H3=G
Cyclic Group: A Cyclic group is a group that is its own cyclic subgroup. The element that
generates cyclic subgroup can also generates group itself.This element is referred as
generator „g‟.
Example: In the previous example, The group G=<Z3, +> is a cyclic grop with two
generators g=1 and g=2
Lagrange’s Theorem:
It related the order of a group to the order of its sub group. Assme that G is group and H is its
subgroup. If order of G and H are |G| and |H|, respectively, based on this theorem |H| divides
|G|.
Example: As per the previous cyclic subgroup example, |H1|=1, |H2|=3, |H3|=3, Obviously,
all of these orders divide the order of |G|.
Example:
In the group G=<Z3, +>, ord(0)=1, ord(1)=3, ord(2)=3
Rings
A Ring, denoted as R = < {. }, , □ >, is an algebraic structure with two
operations(addition and multiplication).
The first operation must satisfy all five properties required for an abelian group. The second
operation must satisfy only the first two.
In addition, the second operation must be distributed over the first operation.
Commutative Ring: If a ring satisfies commutative property, then we say the ring is a
commutative ring.
• Rings do not need to have a multiplicative inverse.
Example: Z an Integer set is a Ring structure. Explain why Z (set of Integer numbers) is
a ring?
Suppose that 2,3,4∈Z.
Dr. Ram Prasad Reddy Sadi Page 19
UNIT – I – Part - II
Prime numbers
Asymmetric-key cryptography uses prime numbers extensively. A prime is divisible only by
itself and 1.
Example 1:
What is the smallest prime?
The smallest prime is 2, which is divisible by 2 (itself) and 1.
Example 2:
List the primes smaller than 10.
There are four primes less than 10: 2, 3, 5, and 7. It is interesting to note that the percentage
of primes in the range 1 to 10 is 40%. The percentage decreases as the range increases.
Cardinality of Primes
We can use infinite Number of Primes.
Number of Primes
π(x) is the number of primes less than or equal to x. π is not similar to mathematics π.
The primes under 25 are 2, 3, 5, 7, 11, 13, 17, 19 and 23 so π(3) = 2, π(10) = 4 and π(25)
= 9.
Example 1
Find the number of primes less than 1,000,000.
The approximation gives the range 72,383 to 78,543.
The actual number of primes is 78,498.
Checking for Primeness
Given a number n, how can we determine if n is a prime? The answer is that we need to
see if the number is divisible by all primes less than
Example 1:
Is 97 a prime?
The floor of π(97) = 9. The primes less than 9 are 2, 3, 5, and 7. We need to see if 97 is
divisible by any of these numbers. It is not, so 97 is a prime.
Example 2:
Is 301 a prime?
The floor of π(301) = 17. We need to check 2, 3, 5, 7, 11, 13, and 17. The numbers 2, 3,
and 5 do not divide 301, but 7 does. Therefore 301 is not a prime.
Fermat’s Little Theorem
First Version: if p is prime and a is positive integer, then
ap − 1 ≡ 1 mod p
Second Version:
ap ≡ a mod p
This means that if we divide ap by p then the remainder should be „a‟.
Example 1:
Find the result of 610 mod 11.
Multiplicative Inverses
a−1 mod p = a p − 2 mod p
Example
The answers to multiplicative inverses modulo a prime can be found without using
the extended Euclidean algorithm:
Example:
How to calculate multiplicative inverse of 5 modulo 23 that is 5-1 mod 23?
Solution:
1. 5-1 mod 23 = 523-2 mod 23 (Ref: a-1 mod p= ap-2 mod p)
2. 523-2 mod 23 = 521 mod 23
3. Calculate following to solve 521 mod 23:
51 mod 23 = 5
52 mod 23=25 mod 23=2
54 mod 23= (52)2 mod 23= (2)2 mod 23=4
58 mod 23= (54)2 mod 23 (4)2 mod 23=16
516 mod 23= (58)2 mod 23 (16)2 mod23=256 mod 23=3
Now binary equivalence of 21 is 10101, so multiply 51 , 54 and 516 values, leave 52 and 58
because these are
0‟s in binary form.
521 mod 23 = (516 x 54 x 51 ) mod 23=(3x4x5) mod 23=60 mod 23= 14 mod 23.
Finally 5-1 mod 23 = 521 mod 23 = 14 mod 23
Euler’s Theorem
First Version:For every a and n, they are relatively prime then
Dr. Ram Prasad Reddy Sadi Page 23
UNIT – I – Part - II
a ϕ(n) ≡ 1 (mod n)
Second Version
a k × f(n) + 1 ≡ a (mod n)
Note: The second version of Euler‟s theorem is used in the RSA cryptosystem.
Example 2:
Find the result of 624 mod 35.
Solution
We have 624 mod 35 = 6 ϕ (35) mod 35 = 1.
Example :
Find 34 mod 10 ?
Solution
Example 3:
Find the result of 2062 mod 77. Solution
If we let k = 1 on the second version, we have f(77)= f(7)x f(11)=6x10=60
2062 mod 77 = (20 mod 77) (2060+1 mod 77) mod 77=
(20 mod 77) (20f(77) + 1 mod 77) mod 77
= (20)(20) mod 77 = 15.
Multiplicative Inverses
Euler‟s theorem can be used to find multiplicative inverses modulo a composite.
Example:
The answers to multiplicative inverses modulo a composite can be found without
using the extended Euclidean algorithm if we know the factorization of the composite: