Top Banner
Mathematics of Cryptography Bimal Kumar Meher Dept. of CSE/IT Silicon Institute of Technology
73
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: ch-2(CNS)

Mathematics of Cryptography

Bimal Kumar MeherDept. of CSE/IT

Silicon Institute of Technology

Page 2: ch-2(CNS)

To review integer arithmetic, focusing on divisibility and to find the GCD using the Euclidean algorithm

To use Extended Euclidean algorithm to solve linear Diophantine equations, to solve linear congruent equations, and to find the multiplicative inverses

To emphasize the importance of modular arithmetic

To emphasize and review matrices and operations on residue matrices

Objectives

Page 3: ch-2(CNS)

The set of integers, denoted by Z, contains all integral numbers (with no fraction) from negative infinity to positive infinity.

Set of Integers

Page 4: ch-2(CNS)

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.

Binary Operations

Page 5: ch-2(CNS)

In integer arithmetic, if we divide a by n, we can get q and r . The relationship between these four integers can be shown as

Integer Division

a = q × n + r

Page 6: ch-2(CNS)

Continued

Page 7: ch-2(CNS)

Continued

•• When we use a computer or a calculator, When we use a computer or a calculator, rr and and qq are are negative when negative when aa is negative. is negative.

•• How can we apply the restriction that How can we apply the restriction that r r needs to be needs to be positive? positive?

-255=(-23 x 11) + (-2)•• The solution is simple, we decrement the value of The solution is simple, we decrement the value of qq by 1 by 1

and we add the value of and we add the value of nn to to rr to make it positive.to make it positive.

Page 8: ch-2(CNS)

If a is not zero and we let r = 0 in the division relation, we get

Divisbility

a = q × n

If the remainder is zero, n a

If the remainder is not zero, n a

Page 9: ch-2(CNS)

Continued

a.a. The integer 5 divides the integer 30 because The integer 5 divides the integer 30 because 30 = 6 × 5. So, we can write 5 3030 = 6 × 5. So, we can write 5 30

b. The number 8 does not divide the number 42 b. The number 8 does not divide the number 42 because 42 = 5 × 8 + 2. There is a remainder, because 42 = 5 × 8 + 2. There is a remainder, the number 2, in the equation. Hence, 8 42the number 2, in the equation. Hence, 8 42

Page 10: ch-2(CNS)

PropertiesContinued

Property 1: if a|1, then a = ±1.

Property 2: if a|b and b|a, then a = ±b.

Property 3: if a|b and b|c, then a|c.

Property 4: if a|b and a|c, then a|(m × b + n × c), where mand n are arbitrary integers

Page 11: ch-2(CNS)

ContinuedExample

Page 12: ch-2(CNS)

ExampleContinued

Page 13: ch-2(CNS)

Continued

Fact 1: The integer 1 has only onedivisor, itself.

Fact 2: Any positive integer has at least two divisors, 1 and itself (but itcan have more).

Note

Page 14: ch-2(CNS)

ContinuedFigure : Common divisors of two integers

Page 15: ch-2(CNS)

Continued

The greatest common divisor of two positive integers is the largest integer that can divide both integers.

Note Greatest Common Divisor

Euclidean Algorithm

Fact 1: gcd (a, 0) = aFact 2: gcd (a, b) = gcd (b, r), where r is

the remainder of dividing a by b

Note

Page 16: ch-2(CNS)

ContinuedFigure :Euclidean Algorithm

Page 17: ch-2(CNS)

Continued

When gcd (a, b) = 1, we say that a and b are relatively prime.

Note

Page 18: ch-2(CNS)

Example Continued

Find the greatest common divisor Find the greatest common divisor ofof 2740 and 1760.2740 and 1760.

We have We have gcdgcd (2740, 1760) = 20.(2740, 1760) = 20.SolutionSolution

Page 19: ch-2(CNS)

ExampleContinued

Find the greatest common divisor of 25 and 60.Find the greatest common divisor of 25 and 60.

Solution:Solution:We have We have gcdgcd (25, 65) = 5.(25, 65) = 5.

Page 20: ch-2(CNS)

Extended Euclidean AlgorithmContinued

Given two integers Given two integers aa and and bb, we often need to , we often need to find other two integers, find other two integers, ss and and tt, such that, such that

The extended Euclidean algorithm can calculate The extended Euclidean algorithm can calculate the the gcdgcd ((aa, , bb) and at the same time calculate the ) and at the same time calculate the value of value of ss and and tt..

Page 21: ch-2(CNS)

ContinuedExtended Euclidean algorithm, part a

Page 22: ch-2(CNS)

ContinuedExtended Euclidean algorithm, part b

Page 23: ch-2(CNS)

Example Continued

Given Given aa = 161 and = 161 and bb = 28, find = 28, find gcdgcd ((aa, , bb) and the ) and the values of values of ss and and tt..SolutionSolutionWe get We get gcdgcd (161, 28) = 7, (161, 28) = 7, ss = −1 and = −1 and tt = 6.= 6.

Page 24: ch-2(CNS)

Example Continued

Given Given aa = 17 and = 17 and bb = 0, find = 0, find gcdgcd ((aa, , bb) and the ) and the values of values of ss and and tt..

SolutionSolutionWe get We get gcdgcd (17, 0) = 17, (17, 0) = 17, ss = 1, and = 1, and tt = 0= 0..

Page 25: ch-2(CNS)

Linear Diophantine EquationContinued

A linear Diophantine equation of two variables is ax + by = c.

Note

Page 26: ch-2(CNS)

Linear Diophantine EquationContinued

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

Note

Page 27: ch-2(CNS)

Example Continued

Find the particular and general solutions to the Find the particular and general solutions to the equation 21equation 21xx + 14+ 14yy = 35.= 35.

Page 28: ch-2(CNS)

ExampleContinued

Imagine we want to change Imagine we want to change RsRs.100.100 in in denominations of denominations of RsRs.20.20 and and RsRs.5.5 from a teller from a teller counter of a bank. Find the possible solutions.counter of a bank. Find the possible solutions.

We have many choices, which we can find by We have many choices, which we can find by solving the corresponding solving the corresponding DiophantineDiophantine equationequation2020xx + 5+ 5yy = 100.= 100.

Since d = gcd (20, 5) = 5 and 5 | 100, the equation has anInfinite 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).

Page 29: ch-2(CNS)

MODULAR ARITHMETICMODULAR 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.

1. Modular Operator2. Set of Residues3. Congruence4. Operations in Zn5. Addition and Multiplication Tables6. Different Sets

Topics we will discuss this section:

Page 30: ch-2(CNS)

• The modulo operator is shown as mod. • The second input (n) is called the modulus.• The output r is called the residue.

Modulo Operator

Figure : Division algorithm and modulo operator

Page 31: ch-2(CNS)

ExampleContinued

Find the result of the following operations:a. 27 mod 5 b. 36 mod 12c. −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 r = 10

d. Dividing −7 by 10 results in r = −7. After adding the modulus to −7, r = 3.

Page 32: ch-2(CNS)

The modulo operation creates a set, which in modular arithmetic is referred to as the set of least residues modulo n, or Zn.

Set of Residues

Figure : Some Zn sets

Page 33: ch-2(CNS)

To show that two integers are congruent, we use the congruence operator ( ≡ ). For example, we write:

Congruence

Page 34: ch-2(CNS)

ContinuedFigure Concept of congruence

Page 35: ch-2(CNS)

A residue class [a] or [a]n is the set of integers congruent modulo n.

ContinuedResidue Classes

Page 36: ch-2(CNS)

Example Continued

Can you give an example of modular arithmetic, usedin our daily life ?

We use modular arithmetic in our daily life; for example, we use a clock to measure time. Our clock system uses modulo 12 arithmetic. However, instead of a 0 we use the number 12.

Page 37: ch-2(CNS)

• 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.

Operation in Zn

Figure Binary operations in Zn

Page 38: ch-2(CNS)

Example Continued

Perform the following operations (the inputs come from Zn):a. Add 7 to 14 in Z15.b. Subtract 11 from 7 in Z13.c. Multiply 11 by 7 in Z20.

Page 39: ch-2(CNS)

PropertiesContinued

Page 40: ch-2(CNS)

ContinuedFigure Properties of mod operator

Page 41: ch-2(CNS)

Example Continued

The following shows the application of the above properties:

1. (1,723,345 + 2,124,945) mod 11 = (8 + 9) mod 11 = 6

2. (1,723,345 − 2,124,945) mod 16 = (8 − 9) mod 11 = 10

3. (1,723,345 × 2,124,945) mod 16 = (8 × 9) mod 11 = 6

Page 42: ch-2(CNS)

Example Continued

In arithmetic, we often need to find the remainder of powers of 10 when divided by an integer.

Page 43: ch-2(CNS)

ExampleContinued

• Note 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.

Page 44: ch-2(CNS)

Inverses

• In modular arithmetic, we often need to find the inverse of a number relative to an operation.

• It can be an additive inverse (relative to an addition operation) or a multiplicative inverse(relative to a multiplication operation).

Page 45: ch-2(CNS)

ContinueAdditive 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.

Note

Page 46: ch-2(CNS)

ExampleContinued

Find all additive inverse pairs in Z10.

The six pairs of additive inverses are (0, 0), (1, 9), (2, 8), (3, 7), (4, 6), and (5, 5).

Page 47: ch-2(CNS)

Continue

In Zn, two numbers a and b are the multiplicative inverse of each other if

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.

Note

Page 48: ch-2(CNS)

Example 1

Continued

Find the multiplicative inverse of 8 in Z10.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

Find all multiplicative inverses in Z10.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.

Page 49: ch-2(CNS)

ExampleContinued

Find all multiplicative inverse pairs in Z11.

We have seven pairs: (1, 1), (2, 6), (3, 4), (5, 9), (7, 8), (9, 9), and (10, 10).

Page 50: ch-2(CNS)

Continued

The extended Euclidean algorithm finds the multiplicative inverses of b in Zn

when n and b are given and gcd (n, b) = 1.

The multiplicative inverse of b is the value of t after being mapped to Zn.

Note

Page 51: ch-2(CNS)

ContinuedFigure Using extended Euclidean algorithm to

find multiplicative inverse

Page 52: ch-2(CNS)

ExampleContinued

Find the multiplicative inverse of 11 in Z26.

The gcd (26, 11) is 1; the inverse of 11 is −7 or 19.

Page 53: ch-2(CNS)

Example Continued

Find the inverse of 12 in Z26.

The gcd (26, 12) is 2; the inverse does not exist.

Page 54: ch-2(CNS)

Different SetsFigure Some Zn and Zn* sets

We need to use Zn when additive inverses are needed; we need to use Zn* when multiplicative inverses are needed.

Note

Page 55: ch-2(CNS)

Two More Sets

• Cryptography often uses two more sets:• Zp and Zp*.• The modulus in these two sets is a prime

number.

Page 56: ch-2(CNS)

MATRICESMATRICES

•• In cryptography we often need to handle matrices. In cryptography we often need to handle matrices. •• Therefore, we briefly review the following topics . Therefore, we briefly review the following topics .

DefinitionsOperations and RelationsDeterminantsResidue Matrices

Topics discussed in this section:Topics discussed in this section:

Page 57: ch-2(CNS)

Definition

Figure : A matrix of size l × m

Page 58: ch-2(CNS)

Continued

Figure Examples of matrices

Page 59: ch-2(CNS)

Operations and RelationsExample

Addition and SubtractionAddition and Subtraction

Page 60: ch-2(CNS)

Continued Example

Multiplication of a row matrix by a column matrix

Page 61: ch-2(CNS)

Continued Example

Multiplication of a 2 × 3 matrix by a 3 × 4 matrix

Page 62: ch-2(CNS)

Continued Example

Scalar multiplication

Page 63: ch-2(CNS)

Determinant

The determinant of a square matrix A of size m × m denoted as det (A) is a scalar calculated recursively as shown below:

The determinant is defined only for a square matrix.

Note

Page 64: ch-2(CNS)

Continued Example

Calculating the determinant of a 2 × 2 matrix based on the determinant of a 1 × 1 matrix.

Page 65: ch-2(CNS)

Continued Example

Calculate the determinant of a 3 × 3 matrix given by:

5 2 13 0 -42 1 6

Page 66: ch-2(CNS)

Inverses

Multiplicative inverses are only defined for square matrices.

Note

Page 67: ch-2(CNS)

Residue Matrices

• Cryptography uses residue matrices.• Matrices where all elements are in Zn. • A residue matrix has a multiplicative inverse if

gcd (det(A), n) = 1.Example: A residue matrix and its multiplicative inverse

Page 68: ch-2(CNS)

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).

1 Single-Variable Linear Equations2 Set of Linear Equations

Topics discussed in this section:

Page 69: ch-2(CNS)

Single-Variable Linear Equations

Equations of the form ax ≡ b (mod n ) might have no solution or a limited number of solutions.

Steps to find out the solutions if d divides b1. Reduce the equation by dividing both sides by d.2. Multiply both sides by the multiplicative inverse of a

to find the particular solution x0.3. The general solns are: x=x0+k(n/d) for k=0,1,…,(d-1)

Page 70: ch-2(CNS)

Example 1

Continued

Solve the equation 10 x ≡ 2(mod 15).First we find the First we find the gcdgcd (10 and 15) = 5. Since 5 does not (10 and 15) = 5. Since 5 does not divide 2, we have no solution.divide 2, we have no solution.

Solve the equation 14 x ≡ 12 (mod 18).Example 2

Page 71: ch-2(CNS)

Example Continued

Solve the equation 3x + 4 ≡ 6 (mod 13).

• 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).

Page 72: ch-2(CNS)

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.

Set of linear equations

Page 73: ch-2(CNS)

Example

Continued

Solve the set of following three equations:

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.