21.1 KB · commit a9602da
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. We will discuss some classical ciphers, including shift ciphers, which replace each letter by the letter a fixed number of positions later in the alphabet, wrapping around to the beginning of the alphabet when necessary. The classical ciphers we will discuss are examples of private key ciphers where knowing how to encrypt allows someone to also decrypt messages. With a private key cipher, two parties who wish to communicate in secret must share a secret key. The classical ciphers we will discuss are also vulnerable to cryptanalysis, which seeks to recover encrypted information without access to the secret information used to encrypt the message. We will show how to cryptanalyze messages sent using shift ciphers.
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. Knowing how to encrypt requires that someone know the modulus and an exponent. (It does not require that the two prime factors of the modulus be known.) As far as it is known, knowing how to decrypt requires someone to know how to invert the encryption function, which can only be done in a practical amount of time when someone knows these two large prime factors. In this section we will explain how the RSA cryptosystem works, including how to encrypt and decrypt messages.
The subject of cryptography also includes the subject of cryptographic protocols, which are exchanges of messages carried out by two or more parties to achieve a specific security goal. We will discuss two important protocols in this section. One allows two people to share a common secret key. The other can be used to send signed messages so that a recipient can be sure that they were sent by the purported sender.
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 (sending the last three letters of the alphabet to the first three). For instance, using this scheme the letter B is sent to E and the letter X is sent to A. This is an example of encryption, that is, the process of making a message secret.
To express Caesar’s encryption process mathematically, first replace each letter by an element of Z26, that is, an integer from 0 to 25 equal to one less than its position in the alphabet. For example, replace A by 0, K by 10, and Z by 25. Caesar’s encryption method can be represented by the function f that assigns to the nonnegative integer p, p≤25, the integer f(p) in the set {0,1,2,…,25} with f(p)=(p+3)mod26. In the encrypted version of the message, the letter represented by p is replaced with the letter represented by (p+3)mod26.
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 1924 14 208 1319 7 415 0 17 10. Now replace each of these numbers p by f(p)=(p+3)mod26. This gives 15 7 7 221 17 2311 1622 10 718 3 20 13. Translating this back to letters produces the encrypted message “PHHW BRX LQ WKH SDUN.” ◀
To recover the original message from a secret message encrypted by the Caesar cipher, the function f−1, the inverse of f, is used. Note that the function f−1 sends an integer p from Z26, to f−1(p)=(p−3)mod26. In other words, to find the original message, each letter is shifted back three letters in the alphabet. The process of determining the original message from the encrypted message is called decryption.
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)mod26. Such a cipher is called a shift cipher. Note that decryption can be carried out using f−1(p)=(p−k)mod26. Here the integer k is called a key. We illustrate the use of a shift cipher in Examples 2 and 3.
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 156 11 14 1 0 1122 0 17 12 8 13 6. We now apply the shift f(p)=(p+11)mod26 to each number in this string. We obtain 3 4 25 017 22 25 12 11 227 11 2 23 19 24 17. Translating this last string back to letters, we obtain the ciphertext “DEZA RWZMLW HLCXTYR.” ◀
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 1115 25713 24 11 7 00 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 48 1806 17 4 0 1919 4 0 2 7 4 17. Finally, we translate these numbers back to letters to obtain the plaintext: “EXPERIENCE IS A GREAT TEACHER.” ◀
We can generalize shift ciphers further to slightly enhance security by using a function of the form f(p)=(ap+b)mod26, where a and b are integers, chosen so that f is a bijection. (The function f(p)=(ap+b)mod26 is a bijection if and only if gcd(a,26)=1.) Such a mapping is called an affine transformation, and the resulting cipher is called an affine cipher.
What letter replaces the letter K when the function f(p)=(7p+3)mod26 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)mod26=73mod26=21. Because 21 represents V, K is replaced by V in the encrypted message. ◀
To decrypt messages encrypted using an affine cipher, suppose that c=(ap+b)mod26 with gcd(a,26)=1. To decrypt we need to express p in terms of c. We apply the encrypting congruence c≡ap+b(mod26), and solve it for p. First subtract b from both sides, to obtain c−b≡ap(mod26). Because gcd(a,26)=1, there is an inverse a of a modulo 26. Multiplying both sides by a gives a(c−b)≡aap(mod26). Because aa≡1(mod26), this tells us that p≡a(c−b)(mod26). This determines p because p belongs to Z26.
The process of recovering plaintext from ciphertext without knowledge of both the encryption method and the key is known as cryptanalysis or breaking codes.
The main tool for cryptanalyzing ciphertext encrypted using a shift cipher is the count of the frequency of letters in the ciphertext. The nine most common letters in English text and their approximate relative frequencies are E 13%, T 9%, A 8%, O 8%, I 7%, N 7%, S 7%, H 6%, and R 6%. To cryptanalyze ciphertext produced using a shift cipher, we first find the relative frequencies of letters in the ciphertext. We list the most common letters in the ciphertext in frequency order; we hypothesize that the most common letter in the ciphertext is produced by encrypting E. Then, we determine the value of the shift under this hypothesis, say k. If the message produced by shifting the ciphertext by −k makes sense, we presume our hypothesis is correct. If it does not make sense, we consider the next hypothesis (e.g., T).
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(mod26), 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. ◀
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. We can make it harder to successfully attack ciphertext by replacing blocks of letters with other blocks of letters; such ciphers are called block ciphers.
We will now introduce a simple type of block cipher, called the transposition cipher. As a key we use a permutation σ of the set {1,2,…,m} for some positive integer m, that is, a one-to-one function from {1,2,…,m} to itself. To encrypt a message we first split its letters into blocks of size m. We encrypt the block p1p2…pm as c1c2…cm=pσ(1)pσ(2)…pσ(m). To decrypt a ciphertext block c1c2…cm, we transpose its letters using the permutation σ−1, the inverse of σ.
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,
Solution:
Describe the family of shift ciphers as a cryptosystem.
Solution: To apply the definition of a cryptosystem to shift ciphers, we assume that our messages are already integers, that is, elements of Z26. Consequently, both the set of plaintext strings P and the set of ciphertext strings C are the set of strings of elements of Z26. The set of keys K is the set of possible shifts, so K=Z26. The set E consists of functions of the form Ek(p)=(p+k)mod26, and the set D of decryption functions is Dk(p)=(p−k)mod26. ◀
All classical ciphers, including shift ciphers and affine ciphers, are examples of private key cryptosystems. In a private key cryptosystem, once you know an encryption key, you can quickly find the decryption key. When a private key cryptosystem is used, two parties who wish to communicate in secret must share a secret key.
To avoid the need for keys to be shared by every pair of parties that wish to communicate securely, in the 1970s cryptologists introduced the concept of public key cryptosystems. When such cryptosystems are used, knowing how to send an encrypted message does not help decrypt messages. In such a system, everyone can have a publicly known encryption key. Only the decryption keys are kept secret, and only the intended recipient of a message can decrypt it.
In the RSA 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. 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.
To encrypt messages using a particular key (n,e), we first translate a plaintext message M into sequences of integers. We translate each plaintext letter into a two-digit number (including an initial zero for letters A through J: A is 00, B is 01, ..., J is 09). Then, we concatenate these two-digit numbers into strings of digits. Next, we divide this string into equally sized blocks of 2N digits, where 2N is the largest even number such that the number 2525…25 with 2N digits does not exceed n.
Encryption proceeds by transforming each block M to a ciphertext block C using the function C=Memodn. (To perform the encryption, we use an algorithm for fast modular exponentiation.)
Encrypt the message STOP using the RSA cryptosystem with key (2537,13). Note that 2537=43⋅59, p=43 and q=59 are primes, and gcd(e,(p−1)(q−1))=gcd(13,42⋅58)=gcd(13,2436)=1.
Solution: To encrypt, we first translate the letters in STOP into their numerical equivalents. We then group these numbers into blocks of four digits (because 2525<2537<252525), to obtain 18191415. We encrypt each block using the mapping C=M13mod2537. Computations using fast modular exponentiation show that 181913mod2537=2081 and 141513mod2537=2182. The encrypted message is 2081 2182. ◀
The plaintext message can be quickly recovered from a ciphertext message when the decryption key d, an inverse of e modulo (p−1)(q−1), is known. To see this, note that if de≡1(mod(p−1)(q−1)), there is an integer k such that de=1+k(p−1)(q−1). It follows that Cd≡(Me)d=Mde=M1+k(p−1)(q−1)(modn).
By Fermat’s little theorem (assuming that gcd(M,p)=gcd(M,q)=1), it follows that Mp−1≡1(modp) and Mq−1≡1(modq). Consequently, Cd≡M⋅(Mp−1)k(q−1)≡M⋅1=M(modp) and Cd≡M⋅(Mq−1)k(p−1)≡M⋅1=M(modq). Because gcd(p,q)=1, it follows by the Chinese remainder theorem that Cd≡M(modpq).
We receive the encrypted message 0981 0461. What is the decrypted message if it was encrypted using the RSA cipher from Example 8?
Solution: The message was encrypted using the RSA cryptosystem with n=43⋅59 and exponent 13. As shown in Section 4.4, d=937 is an inverse of 13 modulo 42⋅58=2436. We use 937 as our decryption exponent. Consequently, to decrypt a block C, we compute M=C937mod2537. To decrypt the message, we use fast modular exponentiation to compute: 0981937mod2537=0704and0461937mod2537=1115. Consequently, the numerical version of the original message is 0704 1115. Translating this back to English letters, we see that the message is HELP. ◀
Why is the RSA cryptosystem suitable for public key cryptography? First, it is possible to rapidly construct a public key by finding two large primes p and q, each with more than 200 digits, and finding an integer e relatively prime to (p−1)(q−1). When we know the factorization of the modulus n, that is, when we know p and q, we can quickly find an inverse d of e modulo (p−1)(q−1) using the Euclidean algorithm. Knowing d lets us decrypt messages sent using our key. However, no method is known to decrypt messages that is not based on finding a factorization of n.
Factorization is believed to be a difficult problem, as opposed to finding large primes p and q, which can be done quickly. The most efficient factorization methods known require billions of years to factor 400-digit integers. Consequently, when p and q are 200-digit primes, it is believed that messages encrypted using n=pq cannot be decrypted in a reasonable time unless p and q are known.
Suppose that Alice and Bob want to share a common key over an insecure channel. The Diffie-Hellman protocol follows these steps, where computations are done in Zp:
At the end of this protocol, Alice and Bob have computed their shared key, namely: (ak2)k1modp=(ak1)k2modp.
To find the secret information from the public information (p,a,ak1modp, and ak2modp) requires that an adversary solve instances of the discrete logarithm problem. With current computing power, this system is considered unbreakable when p has more than 300 decimal digits and k1 and k2 have more than 100 decimal digits each.
Suppose that Alice’s RSA public key is (n,e) and her private key is d. Alice encrypts a plaintext message x using the encryption function E(n,e)(x)=xemodn. She decrypts a ciphertext message y using the decryption function D(n,e)(y)=ydmodn.
Alice wants to send the message M so that everyone who receives the message knows that it came from her. She translates the letters into numerical equivalents and splits the resulting string into blocks m1,m2,…,mk such that 0≤mi≤n. She then applies her decryption function D(n,e) to each block, obtaining D(n,e)(mi),i=1,2,…,k. She sends the result to all intended recipients.
When a recipient receives her message, they apply Alice’s encryption function E(n,e) to each block: E(n,e)(D(n,e)(mi))=mi. Because only Alice knows d, every recipient can be sure it came from Alice.
Suppose Alice’s public RSA cryptosystem key is n=43⋅59=2537 and e=13. Her decryption key is d=937. She wants to send the message “MEET AT NOON” to her friends so that they are sure it came from her. What should she send?
Solution: Alice first translates the message into blocks of digits, obtaining 1204 0419 0019 1314 1413. She then applies her decryption transformation D(2537,13)(x)=x937mod2537 to each block:
1204937mod25370419937mod25370019937mod25371314937mod25371413937mod2537=817,=555,=1310,=2173,=1026.So, the message she sends, split into blocks, is 0817 0555 1310 2173 1026. When one of her friends gets this message, they apply her encryption transformation E(2537,13) to each block to recover the original blocks of digits. ◀
To send signed secret messages, the sender applies RSA encryption using the publicly known encryption key of an intended recipient to each block that was encrypted using the sender’s decryption transformation. The recipient then first applies his private decryption transformation and then the sender’s public encryption transformation.