DATA COMMUNICATION AND
1
NETWORKS/
30-3 ASYMMETRIC-KEY CRYPTOGRAPHY
An asymmetric-key (or public-key) cipher uses two
keys: one private and one public. We discuss two
algorithms: RSA and Diffie-Hellman.
Topics discussed in this section:
RSA
Diffie-Hellman
DATA COMMUNICATION AND
30.2 NETWORKS/
Figure 30.24 RSA
DATA COMMUNICATION AND
30.3 NETWORKS/
Note
In RSA, e and n are announced to the
public; d and are kept secret.
DATA COMMUNICATION AND
30.4 NETWORKS/
Example 30.7
Bob chooses 7 and 11 as p and q and calculates
n = 7 · 11 = 77. The value of = (7 − 1) (11 − 1) or 60.
Now he chooses two keys, e and d. If he chooses e to be
13, then d is 37. Now imagine Alice sends the plaintext 5
to Bob. She uses the public key 13 to encrypt 5.
DATA COMMUNICATION AND
30.5 NETWORKS/
Example 30.7 (continued)
Bob receives the ciphertext 26 and uses the private key 37
to decipher the ciphertext:
The plaintext 5 sent by Alice is received as plaintext 5 by
Bob.
DATA COMMUNICATION AND
30.6 NETWORKS/
Example 30.8
Jennifer creates a pair of keys for herself. She chooses
p = 397 and q = 401. She calculates n = 159,197 and
= 396 · 400 = 158,400. She then chooses e = 343 and
d = 12,007. Show how Ted can send a message to Jennifer
if he knows e and n.
DATA COMMUNICATION AND
30.7 NETWORKS/
Example 30.8 (continuted)
Solution
Suppose Ted wants to send the message “NO” to
Jennifer. He changes each character to a number (from
00 to 25) with each character coded as two digits. He then
concatenates the two coded characters and gets a four-
digit number. The plaintext is 1314. Ted then uses e and n
to encrypt the message. The ciphertext is 1314 343 = 33,677
mod 159,197. Jennifer receives the message 33,677 and
uses the decryption key d to decipher it as 33,677 12,007 =
1314 mod 159,197. Jennifer then decodes 1314 as the
message “NO”. Figure 30.25 shows the process.
DATA COMMUNICATION AND
30.8 NETWORKS/
Figure 30.25 Example 30.8
DATA COMMUNICATION AND
30.9 NETWORKS/
Example 30.9
Let us give a realistic example. We randomly chose an
integer of 512 bits. The integer p is a 159-digit number.
The integer q is a 160-digit number.
DATA COMMUNICATION AND
30.10 NETWORKS/
Example 30.9 (continued)
We calculate n. It has 309 digits:
We calculate . It has 309 digits:
DATA COMMUNICATION AND
30.11 NETWORKS/
Example 30.9 (continued)
We choose e = 35,535. We then find d.
Alice wants to send the message “THIS IS A TEST”
which can be changed to a numeric value by using the
00–26 encoding scheme (26 is the space character).
DATA COMMUNICATION AND
30.12 NETWORKS/
Example 30.9 (continued)
The ciphertext calculated by Alice is C = Pe, which is.
Bob can recover the plaintext from the ciphertext by
using P = Cd, which is
The recovered plaintext is THIS IS A TEST after
decoding.
DATA COMMUNICATION AND
30.13 NETWORKS/
Note
The symmetric (shared) key in the
Diffie-Hellman protocol is
K = gxy mod p.
DATA COMMUNICATION AND
30.14 NETWORKS/
Example 30.10
Let us give a trivial example to make the procedure clear.
Our example uses small numbers, but note that in a real
situation, the numbers are very large. Assume g = 7 and
p = 23. The steps are as follows:
1. Alice chooses x = 3 and calculates R1 = 73 mod 23 = 21.
2. Bob chooses y = 6 and calculates R2 = 76 mod 23 = 4.
3. Alice sends the number 21 to Bob.
4. Bob sends the number 4 to Alice.
5. Alice calculates the symmetric key K = 43 mod 23 = 18.
6. Bob calculates the symmetric key K = 216 mod 23 = 18.
The value of K is the same for both Alice and Bob;
gxy mod p = 718 mod 23 = 18.
DATA COMMUNICATION AND
30.15 NETWORKS/
Figure 30.27 Diffie-Hellman idea
DATA COMMUNICATION AND
30.16 NETWORKS/
Figure 30.28 Man-in-the-middle attack
DATA COMMUNICATION AND
30.17 NETWORKS/