section 2.2: affine ciphers; more modular arithmetic practice hw (not to hand in) from barr textbook...

55
Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker Maplet) Extra Problems Find the following gcd’s Answers a. gcd(30, 40) 10 b. gcd(150, 500) 50 c. gcd(187, 455) 1

Upload: georgina-pearson

Post on 11-Jan-2016

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker

Section 2.2: Affine Ciphers; More Modular Arithmetic

Practice HW (not to hand in)From Barr Textbookp. 80 # 2a, 3e, 3f, 4, 5a, 7, 8

9, 10 (Use affinecipherbreaker Maplet)

Extra ProblemsFind the following gcd’s Answersa. gcd(30, 40) 10b. gcd(150, 500) 50c. gcd(187, 455) 1

Page 2: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker

In shift ciphers, messages are encrypted by using

an additive key. To increase security, we can, in

addition to an additive parameter, encipher

messages using a multiplicative parameter.

In affine ciphers, the key used for encipherment

involves using both a multiplicative and additive

parameter. Before describing affine ciphers, we

give some necessary mathematics background.

Page 3: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker

Mathematics Background for Affine Ciphers

• All natural numbers - numbers in the set

can be expressed as the product of two or more numbers. For example,

, , and .

},5,4,3,2,1{

326 5225420 717

Page 4: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker

Two numbers that can be multiplied together to

get another number are called the factors or

divisors of that number. For example,

• (2 and 3 are the divisors or factors of 6)

• (2 and 5 are factors or divisors of 20).

• (1 and 7 are the divisors or factors of 7).

326

5225420

717

Page 5: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker

Definition

• A natural number p is said to be prime if

and its only divisors are 1 and p. A natural number that is not prime is said to be composite.

1p

Page 6: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker

• It can be shown that there are an infinite number of primes. The following set lists the first ten primes:

The prime numbers provide the building blocks of all numbers. The next theorem illustrates this fundamental fact.

},29,23,19,17,13,11,7,5,3,2{

Page 7: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker

The Fundamental Theorem of Arithmetic

• Every natural number larger than 1 is a product of primes. This factorization can be done in only one way if order is disregarded.

For example, to factor 30, we can compute

orderngdisregardiionfactorizatprimesame

3255235325630

Page 8: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker

• An elementary way to obtain prime factorizations with small prime factors involves the use of a calculator and a factor tree. The next two examples illustrate this technique.

Page 9: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker

Example 1: Factor 90

Solution:

Page 10: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker

Example 2: Factor 935

Solution:

Page 11: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker

Greatest Common Divisor

• The greatest common divisor of two natural numbers a and b, denoted as

, is the largest natural number that divides a and b with no remainder.

),gcd( ba

Page 12: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker

Elementary Method for Computing the gcd of Two Numbers

• Decompose each number into its prime factors. The gcd is obtained by multiplying the prime factors the two numbers have in common. If the two numbers have no common prime factors, then the gcd = 1.

Page 13: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker

Example 3: Find the gcd(20, 30).

Solution:

Page 14: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker

Example 4: Find the gcd(1190, 935).

Solution:

Page 15: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker

Example 5: Find the gcd(15, 26).

Solution:

Page 16: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker

Note

• Two numbers a and b where the are said to be relatively prime.

1),gcd( ba

Page 17: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker

Example 6: Fill in the ( ) for , ,

and if we are working in the real number

system.

Solution:

1)2( 1)10( 1)( a

Page 18: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker

Multiplicative Inverses

• In the real number system, every non-zero number has a multiplicative inverse – the number you must multiply to a given number to get 1.

Page 19: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker

*Note

• In some number systems, multiplicative inverses in most cases do not exist.

Example 7: Solve and using

the integers

Solution:

1)2( 1)10( },4,3,2,1,0,1,2,3,4,{

Page 20: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker
Page 21: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker

Fact

• In the modular arithmetic system, a multiplicative inverse may or may not exist, depending on the following fact involving the gcd:

If the , then b has an inverse with respect to the modulus m, that is, exists.

1),gcd( mb1b

Page 22: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker

Example 8: Does 8 have an inverse with respect

to the modulus 26?

Solution:

Page 23: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker

Example 9: Does 9 have and inverse with

respect to the modulus 26?

Solution:

Page 24: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker

Later in the course, we will see a general

mathematical method for computing multiplicative

inverses. For now, since we will work with a MOD

26 system, we will display a table showing the

numbers in a MOD 26 with their multiplicative

inverses:

Page 25: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker

MOD 26 Multiplicative Inverse Table

a

261MODa

1 3 5 7 9 11 15 17 19 21 23 25

1 9 21 15 3 19 7 23 11 5 17 25

Page 26: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker

Example 10: Use the multiplicative inverse table

to find MOD 26.

Solution:

17

Page 27: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker

• Multiplicative inverses expand our ability to solve equations and congruences in modular arithmetic. This is made possible using the multiplicative property of modular arithmetic, which we state next.

Multiplicative Property for Modular Arithmetic

If , then

for any number k.

mba mod

mkbka mod

Page 28: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker

Example 11: Solve mod 26 for x.

Solution:

5111 x

Page 29: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker
Page 30: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker

• Multiplicative inverses in modular arithmetic can be useful in solving systems of linear equations, which are useful for cryptanalysis. This next example illustrates this fact.

Page 31: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker

Example 12: Solve the system of equations

(congruences)

Solution:

26mod1117

26mod188

ba

ba

Page 32: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker
Page 33: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker
Page 34: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker
Page 35: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker

Mathematical Description of Affine Ciphers

• Given a and b in where .

We encipher a plaintext letter x to obtain a ciphertext letter y by computing

MOD 26.

Here, the key is made up of a multiplicative parameter a and an additive parameter b.

}25,24,,2,1,0{26 Z1)26,gcd( a

)( baxy

Page 36: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker

Example 13: Encipher “RADFORD” using the

affine cipher MOD 26.

Solution:

)45( xy

Page 37: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker
Page 38: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker

Note

Recall that for an affine cipher MOD 26

to be defined properly, .

Besides allowing a recipient to decipher a

message, the next example illustrates another

reason why this requirement is essential.

)( baxy 1)26,gcd( a

Page 39: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker

Example 14 Use the affine cipher

MOD 26 to encipher “AN”.

Solution:

)12( xy

Page 40: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker

Deciphering an Affine Cipher

• For an affine cipher where

, decipherment can be done uniquely. Given the numerical representation of the plaintext message x and ciphertext message y , we take

26mod)( baxy

1)26,gcd( a

26mod)( baxy

Page 41: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker
Page 42: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker
Page 43: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker

Example 15: Decipher the message

“ARMMVKARER” that was encrypted using the

affine cipher

• Solution:

26)53( MODxy

Page 44: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker
Page 45: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker
Page 46: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker

Cryptanalysis of Affine Ciphers

• For an affine cipher MOD 26, an enemy must know the multiplicative parameter a and additive parameter b in order to decipher and break a message. Once a and b are known,

MOD 26

can be computed and the message broken. Two methods of attack can be used to attempt to break an affine cipher.

)( baxy

)(1 byax

Page 47: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker

Methods for Breaking and Affine Cipher

1. Exhaustion. Note there are 12 possible

multiplicative parameters a where

gcd(a, 26) = 1 and 26 possible additive parameters b . This gives total pairs to test.

3122612 ),( ba

Page 48: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker

2. Frequency analysis. Quicker way which

involves matching to highly frequently occurring ciphertext letters with two highly frequently occurring plaintext letters. Involves solving a system of equations MOD 26.

The next example illustrates method 2.

Page 49: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker

Example 16: Suppose we receive a ciphertext

that was enciphered using an affine cipher. After

running a frequency analysis on the ciphertext,

we find out that the most highly frequently

occurring letters in the ciphertext are W and H.

Assuming that these letters correspond to E and

T respectively, find the parameters and that

were used in the affine cipher.

Page 50: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker

Solution: Recall that for an affine cipher

x is the numerical representation of the plaintext

letter and y is the numerical representation of the

ciphertext letter. Hence, using the MOD 26

alphabet assignment and the equation

, we see that

26mod)( baxy

26mod)( baxy

Page 51: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker

Plaintext corresponds to the ciphertext which gives the equation

(1)

Plaintext corresponds to the ciphertext which gives the equation

(2)

Rearranging and putting these equations together gives

4 xE22 yW

26mod)4(22 ba

19 xT

7 yH

26mod)19(7 ba

Page 52: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker

(1)

(2)

To find a, we must solve this system of equations.

To eliminate the parameter b, we subtract

equation (2) from equation (1):

26mod224 ba26mod719 ba

26mod1515

26mod719

26mod224

a

ba

ba

Page 53: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker

Since , we can write the

resulting equation from the subtraction as:

We next solve this result by multiplying both sides

by :

Noting from the MOD 26 multiplicative inverse

table that , we obtain

1126MOD15

26mod1511 a

111

26mod15111111 11 a

1926mod11 1

Page 54: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker

Hence a = 25. We can substitute a = 25 into

either equation (1) or (2) to find b. Choosing

equation (1) , we obtain:

or

2526mod28526mod1519 a

26mod224 ba

26mod22)25(4 b

26mod22100 b

Page 55: Section 2.2: Affine Ciphers; More Modular Arithmetic Practice HW (not to hand in) From Barr Textbook p. 80 # 2a, 3e, 3f, 4, 5a, 7, 8 9, 10 (Use affinecipherbreaker

Subtracting 100 from both sides gives

or

Hence a = 25 and b = 0 solves the above system

of equations. Hence, the affine cipher

y = (25x + 0) mod 26 = 25x mod 26

was used to encrypt the message.

26mod)10022( b

026mod78 b