Discrete Math
Cryptography I
Page 1 of 4
Encryption uses a bijective function to encrypt/decrypt a plaintext message m to/from a ciphertext c.
Computers can use formulas with modular arithmetic to encrypt/decrypt messages.
The Caesar cipher is an example of encryption that shifts the alphabet. This encryption can be programmed by assigning letters to numbers and using modular addition:
Assign the space character and each of the 26 uppercase letters a number between 0 and 26 (this is
called an encoding):
A B C D E F G H I
J K L M
0 1 2 3 4 5 6 7 8 9 10 11 12 13
N O P Q R S T U V W X Y Z
14 15 16 17 18 19 20 21 22 23 24 25 26
Choose a key value to shift the alphabet by.
Encrypt plaintext character m into ciphertext using c = (m + key)%27.
Decrypt ciphertext character c into plaintext using m = (c − key)%27.
1. Answering the following using a key value of 23:
(a) Encrypt the space character and the letters A, E, I.
(b) Decrypt the space character and the letters A, N, P.
(c) Encrypt the message “CAESAR CIPHER”.
(d) Decrypt the ciphertext “OAZNAPWZK A”.
Discussion Points:
Expressing messages as numbers allows encrypting/decrypting using modular arithmetic.
Modular addition/subtraction shifts the list forwards/backwards.
The same key is needed to both encrypt and decrypt.
Discrete Math
Cryptography I
Page 2 of 4
A product cipher uses modular multiplication to shuffle and unshuffle the alphabet:
Find two numbers, key1 and key2, such that (key1 · key2)%27 = 1
Encrypt plaintext character m into ciphertext using c = (m · key1)%27.
Decrypt ciphertext character c into plaintext using m = (c · key2)%27.
2. Let key1 = 7 and key2 = 4.
(a) Compute (key1 · key2)%27. Is this a valid key pair?
(b) Encrypt ‘MATH’ using modular multiplication by key1.
M ∼ 13: Encoding (13 · 7)%27 = 10 ∼ J
T ∼ 20:
A ∼ 1:
H ∼ 8:
(c) Decrypt the above result using modular multiplication by key2.
J ∼ 10: Decoding (10 · 4)%27 = 13 ∼ M
3. Prove that for valid key pairs, key1 and key2, the encrypt and decrypt functions are inverses of each
other by first encrypting m then decrypting the result. What requirement ensures they are inverses?
Discussion Points:
What is the advantage of having different keys to encrypt/decrypt with?
Why is it important that key pairs satisfy (key1 · key2)%N = 1 for N characters?
Discrete Math
Cryptography I
Page 3 of 4
4. The greatest common divisor is related to if it is possible to find a valid key pair:
The greatest common divisor, gcd(n, m), is the largest integer that divides both n and m.
n and m are relatively prime if gcd(n, m) = 1.
In addition the previous lesson also gave the following theorem:
If gcd(key1, N ) = 1 it is possible to find key2 such that (key1 · key2)%N = 1. This says a
key pair exists if the key is relatively prime to the modulus N .
(a) Find the following greatest common divisors:
gcd(9, 27) =
gcd(18, 27) =
gcd(12, 27) =
gcd(14, 27) =
(b) Which of the above pairs are relatively prime?
(c) Which of the above keys 9, 12, 14, 18 have a valid key pair?
5. Determine which of 6 and 16 have a valid key pair then find key2.
Discussion Point: With only a limited number of characters (such as 27), the number of key pairs
are limited and small. What ways can be used to increase N to have bigger keys and more possible
pairs?
Discrete Math
Cryptography I
Page 4 of 4
6. Make a table of powers showing an modulo 5, for the values 0 ≤ a < 5. Is there a power such that
an = 1?
7. A theorem called “Fermat’s Little Theorem” says that for any prime p and any a, 0 < a < p, we
have ap−1 ≡ 1 (mod p). We can use this to encrypt. For simplicity let’s say we just want to send
messages consisting of numbers 1 to 10. We will work modulo 11 (which is a prime, p = 11).
Find two numbers, key1 and key2, such that (key1 · key2)%10 = 1
Encrypt plaintext character m into ciphertext using c = (mkey1)%11.
Decrypt ciphertext character c into plaintext using m = (ckey2)%11.
(a) Let key1 = 7 and key2 = 3.
Compute (key1 · key2)%10. Is this a valid key pair?
Encrypt 1, 2, 3, 4 (raise each one to the 7 power, and take the remainder modulo 11)
Decrypt the result (raise each one to the 3 power, and take the remainder modulo 11)
(b) Prove that for valid key pairs, key1 and key2, the encrypt and decrypt functions are inverses
of each other by first encrypting m then decrypting the result. What requirement ensures they
are inverses?