You are on page 1of 29

DISCRETE STRUCTURES

DEPARTMENT OF COMPUTER SCIENCE

DISCRETE
Sit Dolor Amet
STRUCTURES
Chapter 4
Number Theory and Cryptography
The Chinese Remainder Theorem
EXAMPLE 4

• In the first century, the Chinese mathematician Sun-Tsu asked: There are certain things
whose number is unknown.
• When divided by 3, the remainder is 2; when divided by 5, the remainder is 3; and when
divided by 7, the remainder is 2.
• What will be the number of things?
• This puzzle can be translated into the following question: What are the solutions of the
systems of congruences
x ≡ 2 (mod 3),
x ≡ 3 (mod 5),
x ≡ 2 (mod 7)?
We will solve this system
CHINESE REMAINDER THEOREM

• The Chinese remainder theorem, named after the Chinese heritage of problems involving
systems of linear congruences, states that when the moduli of a system of linear
congruences are pairwise relatively prime, there is a unique solution of the system modulo
the product of the moduli.
THEOREM 2: Let m1, m2,...,mn be pairwise relatively prime positive integers greater than
one and a1, a2,...,an arbitrary integers. Then the system
x ≡ a1 (mod m1),
x ≡ a2 (mod m2),
···
x ≡ an (mod mn)

has a unique solution modulo m = m1m2 ··· mn. (That is, there is a solution x with 0 ≤ x
CHINESE REMAINDER THEOREM
CHINESE REMAINDER THEOREM
Example 5: Illustrates how to use the construction given in our proof of the Chinese remainder theorem to solve a system of congruences.

Consider the 3 congruences from Sun-Tsu’s problem:


x ≡2 ( mod 3),
x ≡3 ( mod 5),
x ≡2 ( mod 7)

Solution:

1. Let m = m1 ∙ m2 ∙ m3 = 3∙ 5 ∙ 7 = 105,

2. Use this formula to find Mk = m/mk

M1 = m/3 = 35, M2 = m/5 = 21, M3 = m/7 = 15

3. Use this formula to find Mkyk ≡ 1 (mod mk) or Mk ≡ 1 (mod mk)

• M1 ≡ 1 (mod m1) = 35 * = 1 mod 3

= 35 * 2 = 1 mod 3

= 2 ; 2 ≡ 1 (mod 3)
CHINESE REMAINDER THEOREM

• M2 ≡ 1 (mod m1) = 21 * = 1 mod 5


= 21 * 1 = 1 mod 5
= 1; 21 ≡ 1 (mod 5);
• M3 ≡ 1 (mod m1) = 15 * = 1 mod 7
= 15 * 1 = 1 mod 7
= 1; 15 ≡ 1 (mod 7)
Hence,
x = a1M1 + a2M2 + a3M3 mod m
x = 2 ∙ 35 ∙ 2 + 3 ∙ 21 ∙ 1 + 2 ∙ 15 ∙ 1 = 233 ≡ 23 (mod 105)
We have shown that 23 is the smallest positive integer that is a simultaneous solution. Check it!
BACK SUBSTITUTION METHOD

• The construction in Theorem 2 provides a general method for solving systems of linear
congruences with pairwise relatively prime moduli, it can be easier to solve a system using
a different method.
• Example 6 illustrates the use of a method known as back substitution.
BACK SUBSTITUTION METHOD

Example 6: Use the method of back substitution to find all integers x such that x ≡ 1 (mod 5), x ≡ 2 (mod 6), and x ≡ 3
(mod 7).
Solution: By Theorem 4 in Section 4.1, the first congruence can be rewritten as x= 5t +1, where t is an integer.
• Substituting into the second congruence yields 5t +1 ≡ 2 (mod 6).
• Solving this tells us that t ≡ 5 (mod 6).
• Using Theorem 4 again gives t = 6u + 5 where u is an integer.
• Substituting this back into x= 5t +1, gives x= 5(6u + 5) +1 = 30u + 26.
• Inserting this into the third equation gives 30u + 26 ≡ 3 (mod 7).
• Solving this congruence tells us that u ≡ 6 (mod 7).
• By Theorem 4, u = 7v + 6, where v is an integer.
• Substituting this expression for u into x= 30u + 26, tells us that x= 30(7v + 6) + 26 = 210u + 206.
Translating this back into a congruence we find the solution x ≡ 206 (mod 210).
PRACTICE

1. Use the construction in the proof of the Chinese remainder theorem to find all solutions to
the system of congruences x ≡ 2 (mod 3), x ≡ 1 (mod 4), and x ≡ 3 (mod 5).
2. Use the construction in the proof of the Chinese remainder theorem to find all solutions to
the system of congruences x ≡ 1 (mod 2), x ≡ 2 (mod 3), x ≡ 3 (mod 5), and x ≡ 4 (mod 11).
Applications of Congruences
APPLICATIONS OF CONGRUENCES

• Congruence's have many applications to discrete mathematics, computer science, and


many other disciplines.
• We will introduce three applications in this section: the use of congruence's to assign
memory locations to computer files, the generation of pseudorandom numbers, and check
digits.
• Suppose that a customer identification number is ten digits long. To retrieve customer files
quickly, we do not want to assign a memory location to a customer record using the ten-
digit identification number. Instead, we want to use a smaller integer associated to the
identification number. This can be done using what is known as a hashing function.
HASHING FUNCTIONS

• The central computer at an insurance company maintains records for each of its customers.
How can memory locations be assigned so that customer records can be retrieved quickly?
• The solution to this problem is to use a suitably chosen hashing function. Records are
identified using a key, which uniquely identifies each customer’s records.
• For instance, customer records are often identified using the Social Security number of the
customer as the key.
• A hashing function h assigns memory location h(k) to the record that has k as its key.
– A common hashing function is h(k) = k mod m, where m is the number of memory
locations.
– Because this hashing function is onto, all memory locations are possible.
– Hashing functions should be easily evaluated so that files can be quickly located. The
function h(k) = k mod m meets this requirement; to find h(k), we need only compute the
remainder when k is divided by m.
HASHING FUNCTIONS

Example 1: Find the memory locations assigned by the hashing function h(k) = k mod 111 to
the records of customers with Social Security numbers 064212848, 037149212, and
107405723.
Solution: Let h(k) = k mod 111.
This hashing function assigns the records of customers with social security numbers as keys
to memory locations in the following manner:
h(064212848) = 064212848 mod 111 = 14,
h(037149212) = 037149212 mod 111 = 65,
h(107405723) = 107405723 mod 111 = 14.
but since location 14 is already occupied, the record is assigned to the next available
position, which is 15.
HASHING FUNCTIONS

The hashing function is not one-to-one as there are many more possible keys than memory
locations.
When more than one record is assigned to the same location, we say a collision occurs.
Here a collision has been resolved by assigning the record to the first free location.
For collision resolution, we can use a linear probing function to find the first free memory
location: h(k,i) = (h(k) + i) mod m, where i runs from 0 to m − 1.
There are many other methods of handling with collisions. You may cover these in a later CS
course.
PRACTICE

1. Which memory locations are assigned by the hashing function h(k) = k mod 97 to
the records of insurance company customers with these Social Security
numbers?
a) 034567981
b) 183211232
c) 220195744
d) 987255335
CRYPTOGRAPHY

• Number theory plays a key role in cryptography, the subject of transforming information
so that it cannot be easily recovered without special knowledge.
• Number theory is the basis of many classical ciphers, first used thousands of years ago,
and used extensively until the 20th century.
• These ciphers encrypt messages by changing each letter to a different letter, or each block
of letters to a different block of letters.
• Number theory is also important in public key cryptography, a type of cryptography
invented in the 1970s.
• In public key cryptography, knowing how to encrypt does not also tell someone how to
decrypt.
• The most widely used public key system, called the RSA cryptosystem, encrypts messages
using modular exponentiation, where the modulus is the product of two large primes.
CLASSICAL CRYPTOGRAPHY

 Julius Caesar created secret messages by shifting each letter three letters forward in the alphabet
(sending the last three letters to the first three letters.)
 For example, the letter B is replaced by E and the letter X is replaced by A. This process of making a
message secret is an example of encryption. Here is how this encryption process works:
– Replace each letter by an integer from Z26, that is an integer from 0 to 25 representing one less than
its position in the alphabet.
– The encryption function is f(p) = (p + 3) mod 26. It replaces each integer p in the set {0,1,2,…,25} by
f(p) in the set {0,1,2,…,25}.
– Replace each integer p by the letter with the position p + 1 in the alphabet.
CAESAR CIPHER

Example 1:
CAESAR CIPHER
CAESAR CIPHER

 Example 2:
CAESAR CIPHER

 Example 3:
PUBLIC KEY CRYPTOGRAPHY
THE RSA CRYPTOSYSTEM

• In the RSA (Rivest–Shamir–Adleman) cryptosystem, each individual has an encryption key


(n, e) where n = pq, the modulus is the product of two large primes p and q, say with 200
digits each, and an exponent e that is relatively prime to (p − 1)(q − 1).
• To produce a usable key, two large primes must be found. This can be done quickly on a
computer using probabilistic primality tests, referred to earlier in this section.
• However, the product of these primes n = pq, with approximately 400 digits, cannot, as far
as is currently known, be factored in a reasonable length of time.
• As we will see, this is an important reason why decryption cannot, as far as is currently
known, be done quickly without a separate decryption key.
THE RSA CRYPTOSYSTEM
RSA ENCRYPTION

Example 4 illustrates how RSA encryption is performed. For practical reasons we use small
primes p and q in this example, rather than primes with 200 or more digits.
Example 4:
RSA DECRYPTION
PRACTICE

• Do practice of Question 1, 2, 3, 4, 5, 7, 8, 9, 10, 24, 25, 26, 27

You might also like