Harvard Algorithms cs124 Notes
Harvard Algorithms cs124 Notes
CS 124
Lecture 14
14-2
14.1.2 DES
The Data Encrytpion Standard, or DES, is a U.S. government sponsored cryptographic method proposed in 1976. It
uses a 56 bit key, again shared by Alice and Bob, and it encodes blocks of 64 bits using a complicated sequence of
bit operations.
Many have suspected that the government engineered the DES standard, so that they could break it easily, but
nobody has shown a simpler method for breaking DES other than trying the 256 possible keys. These days, however,
trying even this large number of keys can be accomplished in just a few days with specialized hardware. Hence DES
is widely considered no longer secure.
14.1.3 RSA
RSA (named after its inventors, Ron Rivest, Adi Shamir, and Len Adleman) was developed around the same time as
DES. RSA is an example of public key cryptography. In public key cryptography, Bob has two keys: a public key,
ke , known to everyone, and a private key, kd , known only to Bob. If Alice (or anyone else) wants to send a message x
to Bob, she encrypts it as e(x) using the public key; Bob then decrypts it using his private key. For this to be secure,
the private key must be hard to compute from the public key, and similarly e(x) must be hard to compute from x.
The RSA algorithm depends on some number theory and simple algorithms, which we will consider before
describing RSA. We will then describe how RSA is efficient and secure.
Lecture 14
14-3
Lecture 14
14-4
Extended-Euclid(a, b)
if b = 0 return(a, 1, 0)
Compute k such that a = bk + (a mod b)
(d, x, y) = Extended-Euclid(b, a mod b)
return((d, y, x ky))
end Extended-Euclid
14.2.4 Exponentiation
Suppose we have to compute xy mod z, for integers x, y, z. Multiplying x by itself y times is one possibility, but
it is too slow. A more efficient approach is to repeatedly square from x, to get x2 mod z, x4 mod z, x8 mod z . . .,
log y
x2
mod z. Now xy can be computed by multiplying together modulo z the powers that correspond to ones in the
binary representation of y.
Lecture 14
14-5
bits long.) Bob computes n = pq, and also computes a random integer e, such that gcd((p 1)(q 1), e) = 1. (An
alternative to choosing e randomly often used in practice is to choose e = 3, in which case p and q cannot equal 1
modulo 3.)
The pair (n, e) is Bobs public key, which he announces to the world. Bobs private key is d = e1 mod (p
1)(q 1), which can be computed by Euclids algorithm. More specifically, (p, q, d) is Bobs private key.
Suppose Alice wants to send a message to Bob. We think of the message as being a number x from the range
[1, n]. (If the message is too big to be represented by a number this small, it must be broken up into pieces; for
example, the message could be broken into bit strings of length log n.) To encode the message, Alice computes
and sends to Bob
e(x) = xe mod n.
Upon receipt, Bob computes
d(e(x)) = (e(x))d mod n.
To show that this operation decodes correctly, we must prove:
Claim 4: d(e(x)) = x.
Proof: We use the steps:
e(x)d = xde = x1+k(p1)(q1) = x mod n.
The first equation recalls the definition of e(x). The second uses the fact that d = e1 mod (p 1)(q 1), and hence
de = 1+ k(p 1)(q 1) for some integer k. The last equality is much less trivial. It will help us to have the following
lemma:
Claim 5: (Fermats Little Theorem) If p is prime, then for a 6= 0 mod p, we have a p1 = 1 mod p.
Proof: Look at the numbers 1, 2, . . . , p 1. Suppose we multiply them all by a modulo p, to get a 1 mod p, a
2 mod p, . . . , a (p 1) mod p. We claim that the two sets of numbers are the same! This is because every pair of
numbers in the second group is different; this follows since if a i = a j mod p, then by multiplying by a1 , we
must have i = j mod p. But if all the numbers in the second group are different modulo p, since none of them are 0,
they must just be 1, 2, . . . , p 1. (To get a feel for this, take an example: when p = 7 and a = 5, multiplying a by the
numbers {1, 2, 3, 4, 5, 6} yields {5, 3, 1, 6, 4, 2}.)
From the above equality of sets of numbers, we conclude
1 2 (p 1) = (a 1) (a 2) (a (p 1)) mod p.
Lecture 14
14-6