2nd Unit Part 1
2nd Unit Part 1
2nd Unit Part 1
• Number theory plays an essentially role both in classical cryptography and modern
cryptography, which plays an essential role in electronic communication. We will
show how the ideas we develop can be used in cryptographical protocols, introducing
protocols for sharing keys and for sending signed messages.
• Number theory, once considered the purest of subjects, has become an essential tool
in providing computer and Internet security.
Divisibility and Modular Arithmetic
Division of an integer by a positive integer produces a quotient and a remainder.
Working with these remainders leads to modular arithmetic, which plays an important
role in mathematics and which is used throughout computer science including
generating pseudorandom numbers, assigning computer memory locations to files,
constructing check digits, and encrypting messages
• If a and b are integers with a = 0, we say that a divides b if there is an integer c such
that b = ac, or equivalently, if b a is an integer . When a divides b we say that a is a
factor or divisor of b, and that b is a multiple of a. The notation a | b denotes that a
divides b. We write a | b when a does not divide b.
THE DIVISION ALGORITHM: Let a be an integer and d a positive integer. Then there are
unique integers q and r, with 0 ≤ r.
• In the equality given in the division algorithm, d is called the divisor, a is called the
dividend, q is called the quotient, and r is called the remainder. This notation is used
to express the quotient and remainder: q = a div d, r = a mod d.
Example: What are the quotient and remainder when 101 is divided by 11?
Solution: We have 101 = 11 · 9 + 2.
Hence, the quotient when 101 is divided by 11 is 9 = 101 div 11, and the remainder is 2
= 101 mod 11.
Division algorithm(a: integer, d: positive integer)
q := 0
r := |a|
while r ≥ d
r := r − d
q := q + 1
if a < 0 and r > 0 then
r := d − r
q := −(q + 1)
return (q, r) {q = a div d is the quotient, r = a mod d is the remainder}
Example: What are the quotient and remainder when −11 is divided by 3?
Solution: We have −11 = 3(−4) + 1.
Hence, the quotient when −11 is divided by 3 is −4 = −11 div 3, and the remainder is 1 =
−11 mod 3.
Note that the remainder cannot be negative. Consequently, the remainder is not −2,
even though
−11 = 3(−3) − 2,
because r = −2 does not satisfy 0 ≤ r < 3.
Modular Arithmetic
• If a and b are integers and m is a positive integer, then a is congruent to b modulo m
if m divides a − b. We use the notation a ≡ b (mod m) to indicate that a is congruent
to b modulo m. We say that a ≡ b (mod m) is a congruence and that m is its modulus
(plural moduli). If a and b are not congruent modulo m, we write a ≡ b (mod m).
• Let a and b be integers, and let m be a positive integer. Then a ≡ b (mod m) if and only
if a mod m = b mod m.
Example: Determine whether 17 is congruent to 5 modulo 6 and whether 24 and 14 are
congruent modulo 6.
Solution: Because 6 divides 17 − 5 = 12, we see that 17 ≡ 5 (mod 6). However, because
24 − 14 = 10 is not divisible by 6, we see that 24 ≡ 14 (mod 6).
Example: Use the definition of addition and multiplication in Zm to find 7 +11 9 and 7 ·11 9.
Solution: Using the definition of addition modulo 11, we find that 7 +11 9 = (7 + 9) mod
11 = 16 mod 11 = 5, and 7 ·11 9 = (7 · 9) mod 11 = 63 mod 11 = 8.
Hence 7 +11 9 = 5 and 7 ·11 9 = 8.
The operations +m and ·m satisfy the properties.
• An integer p greater than 1 is called prime if the only positive factors of p are 1 and
p. A positive integer that is greater than 1 and is not prime is called composite.
Prime factorization
Every integer greater than 1 can be written uniquely as a prime or as the product of two
or more primes where the prime factors are written in order of nondecreasing size.
Example: The prime factorizations of 100, 641, 999, and 1024 are given by
100 = 2 · 2 · 5 · 5 = 2252,
641 = 641,
999 = 3 · 3 · 3 · 37 = 33 · 37,
1024 = 2 · 2 · 2 · 2 · 2 · 2 · 2 · 2 · 2 · 2 = 210.
prime factorization of 7007=72 · 11 · 13
Mersenne primes
Because there are infinitely many primes, given any positive integer there are primes
greater than this integer. There is an ongoing quest to discover larger and larger prime
numbers; for almost all the last 300 years, the largest prime known has been an integer
of the special form 2p − 1, where p is also prime. Such primes are called Mersenne
primes.
• The largest Mersenne prime known is 243,112,609 − 1, a number with nearly 13 million
decimal digits, which was shown to be prime in 2008.
PRIMES AND ARITHMETIC PROGRESSIONS Every odd integer is in one of the two
arithmetic progressions 4k + 1 or 4k + 3, k = 1, 2,.... This was provided by the German
mathematician G. Lejeune Dirichlet, The primes 5, 13, 17, 29, 37, 41,... are in the
arithmetic progression 4k + 1; the primes 3, 7, 11, 19, 23, 31, 43,... are in the
arithmetic progression 4k + 3.
5 = 22 + 1, 17 = 42 + 1, 37 = 62 + 1,
The Twin Prime Conjecture
Twin primes are pairs of primes that differ by 2, p and p + 2 such as 3 and 5, 5 and 7, 11
and 13, 17 and 19, and 4967 and 4969.
Relatively prime
The integers a and b are relatively prime if their greatest common divisor is 1.
Example: The integers 17 and 22 are relatively prime, because gcd(17, 22) = 1.
Let b be a positive integer. If n is a composite positive integer, and bn−1 ≡ 1 (mod n),
then n is called a pseudoprime to the base b.
Example: The integer 341 is a pseudoprime to the base 2 because it is composite (341 =
11 · 31) and as 2340 ≡ 1 (mod 341).
We can use an integer other than 2 as the base when we study pseudoprimes.
Greatest Common Divisors and Least Common Multiples
Let a and b be integers, not both zero. The largest integer d such that d | a and d | b is
called the greatest common divisor of a and b. The greatest common divisor of a and b
is denoted by gcd(a, b).
Example: What is the greatest common divisor of 24 and 36?
Solution: The positive common divisors of 24 and 36 are 1, 2, 3, 4, 6, and 12. Hence,
gcd(24, 36) = 12.
The Euclidean Algorithm Computing the greatest common divisor of two integers
directly from the prime factorizations of these integers is inefficient. The reason is that
it is time-consuming to find prime factorizations. We will give a more efficient method
of finding the greatest common divisor, called the Euclidean algorithm.
ALGORITHM: The Euclidean Algorithm.
procedure gcd(a, b: positive integers)
x := a
y := b
while y = 0
r := x mod y
x := y
y := r
return x{gcd(a, b) is x}
Example: Find the greatest common divisor of 414 and 662 using the Euclidean
algorithm.
Solution: Successive uses of the division algorithm give:
662 = 414 · 1 + 248
414 = 248 · 1 + 166
248 = 166 · 1 + 82
166 = 82 · 2 + 2
82 = 2 · 41.
Hence, gcd(414, 662) = 2, because 2 is the last nonzero remainder.
Pseudorandom Numbers
Randomly chosen numbers are often needed for computer simulations. Different
methods have been devised for generating numbers that have properties of randomly
chosen numbers. Because numbers generated by systematic methods are not truly
random, they are called pseudorandom numbers.
The most commonly used procedure for generating pseudorandom numbers is the
linear congruential method. We choose four integers: the modulus m, multiplier a,
increment c, and seed x0.
Classical Cryptography One of the earliest known uses of cryptography was by Julius
Caesar. He made messages secret by shifting each letter three letters forward in the
alphabet.
Encryption
f (p) = (p + 3) mod 26.
Decryption
f −1(p) = (p − 3) mod 26.
Example: What is the secret message produced from the message “MEET YOU IN THE
PARK” using the Caesar cipher?
Solution: First replace the letters in the message with numbers.
This produces 12 4 4 19 24 14 20 8 13 19 7 4 15 0 17 10.
Now replace each of these numbers p by f (p) = (p + 3) mod 26.
This gives 15 7 7 22 1 17 23 11 16 22 10 7 18 3 20 13. Translating this back to
letters produces the encrypted message “PHHW BRX LQ WKH SDUN.”
shift cipher
There are various ways to generalize the Caesar cipher. For example, instead of shifting
the numerical equivalent of each letter by 3, we can shift the numerical equivalent of
each letter by k, so that f (p) = (p + k) mod 26. Such a cipher is called a shift cipher. Note
that decryption can be carried out using f −1(p) = (p − k) mod 26.
Example: Encrypt the plaintext message “STOP GLOBAL WARMING” using the shift cipher
with shift k = 11.
Solution: To encrypt the message “STOP GLOBAL WARMING” we first translate each letter
to the corresponding element of Z26.
This produces the string 18 19 14 15 6 11 14 1 0 11 22 0 17 12 8 13 6.
We now apply the shift f (p) = (p + 11) mod 26 to each number in this string.
We obtain 3 4 25 0 17 22 25 12 11 22 7 11 2 23 19 24 17.
Translating this last string back to letters, we obtain the ciphertext “DEZA RWZMLW
HLCXTYR.
Example: What letter replaces the letter K when the function f (p) = (7p + 3) mod 26 is
used for encryption?
Solution: First, note that 10 represents K. Then, using the encryption function specified, it
follows that f (10) = (7 · 10 + 3) mod 26 = 21. Because 21 represents V, K is replaced by V
in the encrypted message.
Example: Decrypt the ciphertext message “LEWLYPLUJL PZ H NYLHA ALHJOLY” that was
encrypted with the shift cipher with shift k = 7.
Solution: To decrypt the ciphertext “LEWLYPLUJL PZ H NYLHA ALHJOLY” we first translate
the letters back to elements of Z26. We obtain 11 4 22 11 24 15 11 20 9 11 15 25 7 13
24 11 7 0 0 11 7 9 14 11 24.
Next, we shift each of these numbers by −k = −7 modulo 26 to obtain 4 23 15 4 17 8 4 13 2
4 8 18 0 6 17 4 0 19 19 4 0 2 7 4 17. Finally, we translate these numbers back
to letters to obtain the plaintext. We obtain “EXPERIENCE IS A GREAT TEACHER.”
CRYPTANALYSIS
The process of recovering plaintext from ciphertext without knowledge of both the
encryption method and the key is known as cryptanalysis or breaking codes.
Example: Suppose that we intercepted the ciphertext message ZNK KGXRE HOXJ MKZY
ZNK CUXS that we know was produced by a shift cipher. What was the original plaintext
message?
Solution: Because we know that the intercepted ciphertext message was encrypted
using a shift cipher, we begin by calculating the frequency of letters in the ciphertext.
We find that the most common letter in the ciphertext is K. So, we hypothesize that the
shift cipher sent the plaintext letter E to the ciphertext letter K. If this hypothesis is
correct, we know that 10 = 4 + k mod 26, so k = 6. Next, we shift the letters of the
message by −6, obtaining THE EARLY BIRD GETS THE WORM. Because this message
makes sense, we assume that the hypothesis that k = 6 is correct.
BLOCK CIPHERS Shift ciphers and affine ciphers proceed by replacing each letter of
the alphabet by another letter in the alphabet. Because of this, these ciphers are
called character or monoalphabetic ciphers. Encryption methods of this kind are
vulnerable to attacks based on the analysis of letter frequency in the ciphertext, as
we just illustrated. We can make it harder to successfully attack ciphertext by
replacing blocks of letters with other blocks of letters instead of replacing individual
characters with individual characters; such ciphers are called block ciphers.
A simple type of block cipher, called the Transposition cipher
Example: Using the transposition cipher based on the permutation σ of the set {1, 2, 3,
4} with σ (1) = 3, σ (2) = 1, σ (3) = 4, and σ (4) = 2,
(a)Encrypt the plaintext message PIRATE ATTACK.
(b)Decrypt the ciphertext message SWUE TRAE OEHS, which was encrypted using this
cipher.
Solution: (a) We first split the letters of the plaintext into blocks of four letters. We
obtain PIRA TEAT TACK. To encrypt each block, we send the first letter to the third
position, the second letter to the first position, the third letter to the fourth position,
and the fourth letter to the second position. We obtain IAPR ETTA AKTC.
(b) We note that σ −1, the inverse of σ, sends 1 to 2, sends 2 to 4, sends 3 to 1, and
sends 4 to 3. Applying σ −1(m) to each block gives us the plaintext: USEW ATER HOSE.
CRYPTOSYSTEMS We have defined two families of ciphers: shift ciphers and affine
ciphers. We now introduce the notion of a cryptosystem, which provides a general
structure for defining new families of ciphers.