RSA Public Key Cryptography
This is Lab 9 from Clint by Hugh Montgomery, edited by Elad Zelingher. All rights reserved to Hugh Montgomery.
For centuries, one of the hazards of cryptography was that a copy of your code book might fall into enemy hands, so that all your encrypted transmissions could then be intercepted and decoded. Worse yet, you might have no way of knowing whether one of your communications stations had been taken over by the enemy: The enemy might be masquerading as one of your own troops. All this changed in 1976 when Whitfield Diffie and Martin Hellman proposed a form of encryption that should be easy to perform but would be difficult to break, even if the encryption procedure were made public. The scheme works like this: Suppose that Bob wants to receive a message from Alice without observers being able to read the message. Bob chooses a very large integer , say , and defines a permutation of the numbers . The algorithm for computing is made public, and in particular is given to Alice. The characters of Alice's message can be associated with digits in a standard way, and the digits can be broken into blocks of length not exceeding 200, so that Alice's message is equivalent to one or more integers , each one in the interval . Thus is the plaintext. Alice computes ; this is the cryptotext; it is also an integer in the interval . Alice sends to Bob. Since an observer may also gain access to , for the security of the communication it is essential that there be no quick algorithm for computing the inverse permutation , since . However, Bob possesses some secret information concerning that allows him to compute quickly, and hence read Alice's message. A permutation with the peculiar property that is easy to compute while is difficult (i.e., would take centuries on the fastest computers) is called a trap door function.
The success of the Diffie-Hellman scheme depends on being able to find trap door functions. This was achieved in 1977 by Ron Rivest, Adi Shamir, and Len Adleman. Their RSA method depends on the number theory that we have been investigating: Bob secretly chooses two 100 -digit primes , and sets . Bob also chooses a large positive integer with the property that . Among the reduced residue classes , the map is a permutation. Bob makes and public, and Alice sends him . (Recall that we have a powering algorithm that makes this easy.) Since Bob knows how to factor , Bob knows the value of . Hence Bob can find a positive integer such that . (We use the extended Euclidean algorithm to solve linear congruences, so this is also fast.) We now show that the map is the inverse permutation that we need. To this end, choose so that , and recall Euler's congruence, which asserts that if then . Hence
Thus the decryption process for Bob is similar to Alice's encryption, but with the parameter replaced by . Note that only Bob can calculate . Even Alice can't read her own message, once she's encoded it!
In the RSA method, the permutation being employed constitutes a trap door function only to the extent that large composite integers are difficult to factor. In the present state of knowledge one can factor a number of size , but there is no guarantee that there does not exist some factoring method yet to be discovered by which even much larger numbers could be factored quickly. One could imagine that such a method might be taken as a State Secret. Indeed, when Rivest, Shamir, and Adleman published their work in 1978, the Director of the National Security Agency (General Odum) gave serious consideration to going to Congress asking for legislation that would make all research in number theory "born classified" as is the case with atomic research. He was dissuaded from this, but in any case any lingering impression that number theory is the purest of the pure, totally devoid of practical application, has been forever dispelled.
Rivest, Shamir and Adleman patented their method, and formed the company RSA Data Systems to market RSA-based products. To emphasize the security of their system, they offered a prize of $100 for the first decryption of the message
which was encrypted using the 129-digit modulus
and the public exponent
The estimate at that time was that it would take 40 trillion years to factor this . However, on 29 April, 1994, Derek Atkins, Michael Graff, Arjen Lenstra, and Paul Leyland announced that where
This enabled them to determine the secret exponent,
and consequently the plaintext
After conversion back to alphabetic characters, this reads
THE MAGIC WORDS ARE SQUEAMISH OSSIFRAGE
Lenstra (at Bellcore) and his team used the double large prime variation of the multiple polynomial quadratic sieve factoring method. The calculation took more than 5000 mips years, and was executed over a period of 8 months on over 600 different computers that were made available for the purpose by volunteers in more than 20 countries, on all continents except Antarctica. The final stage of the computation took 45 hours on a 16 K MasPar MP-1 massively parallel computer. The relatively short time that it took to factor RSA129 is partly due to increased speed and power of computer hardware, but it is mainly due to progress that has been made in developing faster factoring algorithms.
The RSA-129 modulus was factored by combining the latest factoring algorithms with enormous computing resources. With larger moduli, the RSA method is considered to be secure, and is widely used. In the spring of 1996, Rivest (a mathematician at MIT) sold his interest in the company to a venture capital firm for \ 50,000,000$. So being a mathematician is not only fun, but occasionally also profitable!
The program RSA automates the arithmetic operations that arise when executing the RSA algorithm. To use this program you will need a public modulus, a public exponent, and a secret exponent. Once Bob has the Alice's public key, he can send her an encrypted message by using the RSA program. This program has no word-processing capabilities, so Bob must use the TextToCode program to convert his message to a numerical value. After this, he invokes RSA, where he can and set the variables. Each letter of the text needs to be converted to a two-digit Code; the codes are then concatenated to form a sequence of residues. Each residue is taken to the power modulo to form a new sequence of residues. This is the encryption. In turn, Alice can load the cipher text and her Variables, including her secret decrypting exponent . She can then decrypt to recover the original plaintext sequence of residues. These can be separated to form codes, and finally text, which can be decoded using TextToCode program.
Before proceeding further we consider how to convert characters into numbers. This can be done in many ways. For example, we could let A correspond to 1 , B to , and Z to 26. Alternatively, computers store alphanumeric characters by their ASCII codes. (ASCII is an abbreviation for American Standard Code for Information Interchange.) The first of these methods makes no provision for punctuation, numerals, or lower case letters. The second provides all printable characters, but is inefficient because each character requires three digits (in base 10). The characters that can be typed in the standard keyboard have ASCII codes between 32 (to denote a space ' ') and 126 (for ~). As a compromise between the two systems described above, we subtract 32 from each ASCII code to obtain a 2-digit number. These numbers run from 00 to 94 . In order to preserve the line breaks in a file we need an end of line marker; we assign the code 95 for this purpose. Thus we have the codes opposite.
Problem 1
Suppose that Bob took the (ridiculously small) modulus , and proposed the public exponent . Suppose that Alice sent him the encrypted message . Use the programs Factor, Phi, LinCon, and Power appropriately to recover her plaintext .
Problem 2
The proof above that assumed that . If where and are distinct primes, what is the probability that when is randomly chosen?
Problem 3
Show that if is squarefree then the restriction to is unnecessary. That is, if is squarefree and , then for all integers .
Problem 4
The encrypted message
355456249 475197422 636832086 601788838
was created using the modulus and the public exponent . The program RSA will assist in decrypting this, but first you must determine the value of , and then solve the congruence . (Use Factor and/or Phi, and then LinCon.) Then use TextToCode to decrypt the message. The resulting residues can be separated into 2-digit codes, which may be read as text. What was the message?
Problem 5
Although Bob is the only person who can decrypt a message encrypted with his parameters, he has no way of knowing that the message actually came from Alice, since anyone can use his parameters. To overcome this defect, suppose that Bob has a trap door function and that Alice also has a trap door function . Suppose that Alice sends to Bob. What should Bob do, to decrypt this? Can anyone else decrypt it? Can Bob now be sure that the message came from Alice?
Problem 6
In the preceding problem there was a tacit assumption that the trap door functions and act on the same set of numbers. Suppose now that permutes the residue classes modulo , and that permutes the residue classes modulo . If then we may still proceed as above, since we may consider as lying in the interval , which defines a unique residue class . How would you modify the above procedure if ?
Problem 7
In formulating their challenge, Rivest, Shamir and Adleman did not use the system in the ASCII table to convert from alphanumeric characters to a residue class . By comparing with the stated text can you infer the system that they used
Problem 8
Let , and suppose that you are given the information that has at most two prime factors, and that . Can you find the primes?
Problem 9
Suppose that , so that . In order that ) for all , it is sufficient that , but is it necessary? Suppose that . How many are there, , such that for all ? What if you take instead ? Why is the number of admissible so large? To achieve security, the acceptable should be very rare. How should the prime factors of be chosen, to achieve this?
An RSA code can be broken if the value of is known. One way to determine is to factor , but one could conceive that possibly might be found more quickly, without having to factor . However, we argue now that this is not the case: If the value of is known then the factorization of can be recovered with little work. Hence any quick method of evaluating would yield a quick method of factorization.
If then is prime, and we are done. (Of course such an would not be used for RSA encryption.) Hence we may suppose that , i.e. that is composite.
If is a product of two distinct primes, say , and if is known, then the primes can easily be found. To see this, note that . Since the sum and the product are both known, the values of can be determined. By taking square roots one obtains , and the primes are ( )/2. (This is, after all, how one solves for the roots of a quadratic polynomial.) This procedure may be attempted whenever and are both known. If it fails then we know that is not the product of two distinct primes. To eliminate the (unlikely) possibility that , we may compute .
Now we come to the heart of the matter: is the product of 3 or more primes. Suppose that a number is known with the property that whenever . For example, is such a number . It is enough to find a proper divisor of , since the method may then be applied to the divisors, repeatedly, until all the factors are prime. The number may be hard to factor, but at least we can determine the power of 2 in it, say with odd. Choose a number at random, . If 1 ; then we have found a proper divisor of . If then put . The value of is quickly found by the powering algorithm. By repeated squaring, compute . Actually, there is no need to compute the last term, since this number is . In the sequence of powers of computed, suppose that the first 1 is preceded by a number other than -1 . Then we have an such that , but , and hence is a proper divisor of . This procedure is not guaranteed to work for every , but should work for a large proportion of 's modulo , provided that is divisible by two or more odd primes. (We may assume that is odd.) In the one remaining case, with , the prime can be found quickly, since .
Problem 10
Let . This number is the product of two distinct primes, and . Find the primes.
Problem 11
Let . Given that , show that is not a prime, and is not a product of two primes. (I.e. verify that , that is not a perfect square, and that is not a perfect square.) Use the procedure described above to find the prime factorization of . How many different bases a do you need to consider?