Introduction

Next: Discrete Logarithms and Diffie-Hellman

Exercises

Section 1.1: Simple Substitution Ciphers

1.1. Build a cipher wheel as illustrated in Fig. 1.1, but with an inner wheel that rotates, and use it to complete the following tasks.

(a) Encrypt the following plaintext using a rotation of 11 clockwise.

“A page of history is worth a volume of logic.”

In ROT11: L alrp zq stedzcj td hzces l gzwfxp zq wzrtn

(b) Decrypt the following message, which was encrypted with a rotation of 7 clockwise.

AOLYLHYLUVZLJYLAZILAALYAOHUAOLZLJYLAZAOHALCLYFIVKFNBLZZLZ

Apply ROT(-7): THEREARENOSECRETSBETTERTHANTHESECRETSTHATEVERYBODYGUESSES

(c) Decrypt the following message, which was encrypted by rotating 1 clockwise for the first letter, then 2 clockwise for the second letter, etc.

XJHRFTMZHMZGAHIUETXZJNBWNUTRHEPOMDNBJMAUGORFAOIZOCC

1.2. Decrypt each of the following Caesar encryptions by trying the various possible shifts until you obtain readable text.

(a) LWKLQNWKDWLVKDOOQHYHUVKHDELOOERDUGORYHOBDVDWHH

(b) UXENRBWXCUXENFQRLQJUCNABFQNWRCJUCNAJCRXWORWMB

(c) BGUTBMBGZTFHNLXMKTIPBMAVAXXLXTEPTRLEXTOXKHHFYHKMAXFHNLX

1.3. For this exercise, use the simple substitution table given in Table 1.11.

abcdefghijklmnopqrstuvwxyz
SCJAXUFBQKTPRWEZHVLIGYDNMO

(a) Encrypt the plaintext message:

The gold is hidden in the garden.

(b) Make a decryption table, that is, a table in which the ciphertext alphabet is in order from A to Z and the plaintext alphabet is mixed up.

(c) Use your decryption table from (b) to decrypt the following message.

IBXLX JVXIZ SLLDE VAQLL DEVAU QLB

1.4. Each of the following messages has been encrypted using a simple substitution cipher. Decrypt them. For your convenience, we have given you a frequency table and a list of the most common bigrams that appear in the ciphertext. (If you do not want to recopy the ciphertexts by hand, they can be downloaded or printed from the web site listed in the preface.)

(a) “A Piratical Treasure” (316 letters):

JNRZR BNIGI BJRGZ IZLQR OTDNJ GRIHT USDKR ZZWLG OIBTM NRGJN
IJTZJ LZISJ MRSBL QVRSI ORIQT QDEKJ JNRQW GLOFN IJTZX QLFQL
WBJMJ ITQXT ZJHTB LKUHQL JZKMM LZRNT OBIMIEURLW BLQZJ GKBJT
QDIQSL WJNRO LGRIE ZJGKZ RBGSM JLDGI MNZTQ IHRKM OSOQH IJL
QJBRNJVQAYCIAAWNVWQPVSNSXVJQSWCNODIXGJQAEVOOXCSXXCG
MRIGJLJNRBGKHRTQJRUURBLJWJNRZIUZTULGIENZLUKJRUSTQZLUK
EURFT JNLKJ JNRXRS

Frequency table:

LetterRJILZTNQBGKUMOSHWFEDXV
Freq333027252420191615151312121098765532

Most frequent bigrams: JN (11 times), NR (8 times), TQ (6 times), and LW, RB, RZ, JL (5 times each).

(b) “A Botanical Code” (253 letters):

KZRNK GJKIP ZBOOB XLCRG BXFAU GJBNG RIXRU XAFGJ BXRME MNKNG
BURIX KJRXR SBUER ISATB UIBNN RTBUM NBIGK EBIGR OCUBR GLUBN
JBGRL SJGLN GJBOR ISLRS BAFFO AZBUN RFAUS AGGBI NGLXM IAZRX
RMNVL GBNAS GJRUE KISRM BOAAZ GLOKW FAUKI NGRIC BEBRI NJAWB
OBNNO ATBZJ KOBRC JKIRR NGBUE BRINK XKBAF QBROA LNMRG MALUF
BBG

Frequency table:

LetterBRGNAIUKOJLXMFSEZCTWPVQ
Freq32282220161614131211101088776532111

Most frequent bigrams: NG and RI (7 times each), BU (6 times), and BR (5 times).

(c) “A Brilliant Detective” (313 letters; all occurrences of the word “the” have been removed from the plaintext):

GS2ES GNUBE SZGUG SNKGX CSUUE QNZOQ EOVJN VKNGX GAHSA WSZZ
BOVUE SIXCQ NQESX NGEUG AHZQA QHNSP CIPQA OIDLV JXGAK CGJCG
SASUB FVQAV CIAWN VWQPV SNSXV JGPCV NODIX GJQAE VOOXC SXXCG
OGOVA XGNVU BAVKX QZVQD LVJXQ EXCQO VKCQG AMVAX VWXCG OOBOX
VZCSO SPPSN VAXUB DVVAX QJQAJ VSUXC SXXCV OVJCS NSJXV NOJQA
MVBSZ VOOSH VSAWX QHGMV GWVSX CSXXC VBSNV ZVNVN SAWQZ ORVXJ
CVOQE JCGUW NVA

Frequency table:

LetterVSXGAOQCNJUZEWBPIHKDMLRF
Freq392922292120201913101110865554321111

Most frequent bigrams: XC (10 times), NV (7 times), and CS, DV, QA, SX (6 times each).

1.5. Suppose that you have an alphabet of 26 letters.

(a) How many possible simple substitution ciphers are there?

(b) A letter in the alphabet is said to be fixed if the encryption of the letter is the letter itself. How many simple substitution ciphers are there that leave:

  • (i) No letters fixed?
  • (ii) At least one letter fixed?
  • (iii) Exactly one letter fixed?
  • (iv) At least two letters fixed?

(Part (b) is quite challenging! You might try doing the problem first with an alphabet of four or five letters to get an idea of what is going on.)


Section 1.2: Divisibility and Greatest Common Divisors

1.6. Let . Use the definition of divisibility to directly prove the following properties of divisibility. (This is Proposition 1.4.)

(a) If and , then .

(b) If and , then .

(c) If and , then and .

1.7. Use a calculator and the method described in Remark 1.9 to compute the following quotients and remainders.

(a) 34787 divided by 353.

(b) 238792 divided by 7843.

(c) 9829387493 divided by 873485.

(d) 1498387487 divided by 76348.

1.8. Use a calculator and the method described in Remark 1.9 to compute the following remainders, without bothering to compute the associated quotients.

(a) The remainder of 78745 divided by 127.

(b) The remainder of 2837647 divided by 4387.

(c) The remainder of 8739287463 divided by 18754.

(d) The remainder of 4536782793 divided by 9784537.

1.9. Use the Euclidean algorithm to compute the following greatest common divisors.

(a) .

(b) .

(c) .

(d) .

1.10. For each of the values in Exercise 1.9, use the extended Euclidean algorithm (Theorem 1.11) to find integers and such that .

1.11. Let and be positive integers.

(a) Suppose that there are integers and satisfying . Prove that .

(b) Suppose that there are integers and satisfying . Is it necessarily true that ? If not, give a specific counterexample, and describe in general all of the possible values of .

(c) Suppose that and are two solutions in integers to the equation . Prove that divides and that divides .

(d) More generally, let and let be a solution in integers to . Prove that every other solution has the form and for some integer . (This is the second part of Theorem 1.11.)

1.12. The method for solving described in Sect. 1.2 is somewhat inefficient. This exercise describes a method to compute and that is well suited for computer implementation. In particular, it uses very little storage.

(a) Show that the following algorithm computes the greatest common divisor of the positive integers and , together with a solution in integers to the equation .

1. Set u = 1, g = a, x = 0, and y = b
2. If y = 0, set v = (g - au)/b and return the values (g, u, v)
3. Divide g by y with remainder, g = qy + t, with 0 ≤ t < y
4. Set s = u - qx
5. Set u = x and g = y
6. Set x = s and y = t
7. Go To Step (2)

(b) Implement the above algorithm on a computer using the computer language of your choice.

(c) Use your program to compute and integer solutions to the equation for the following pairs :

  • (i)
  • (ii)
  • (iii)
  • (iv)

(d) What happens to your program if ? Fix the program so that it deals with this case correctly.

(e) It is often useful to have a solution with . Modify your program so that it returns a solution with and as small as possible. [Hint. If is a solution, then so is .] Redo (c) using your modified program.

1.13. Let be integers with , i.e., the largest positive integer dividing all of is 1. Prove that the equation

has a solution in integers . (Hint. Repeatedly apply the extended Euclidean algorithm, Theorem 1.11. You may find it easier to prove a more general statement in which is allowed to be larger than 1.)

1.14. Let and be integers with . We’ve been using the “obvious fact” that divided by has a unique quotient and remainder. In this exercise you will give a proof.

(a) Prove that the set contains at least one non-negative integer.

(b) Let be the smallest non-negative integer in the set described in (a). Prove that .

(c) Prove that there are integers and satisfying and .

(d) Suppose that with and . Prove that and .


Section 1.3: Modular Arithmetic

1.15. Let be an integer and suppose that

Prove that

(This is Proposition 1.13(a).)

1.16. Write out the following tables for and , as we did in Figs. 1.4 and 1.5.

(a) Make addition and multiplication tables for .

(b) Make addition and multiplication tables for .

(c) Make a multiplication table for the unit group .

(d) Make a multiplication table for the unit group .

1.17. Do the following modular computations. In each case, fill in the box with an integer between and , where is the modulus.

(a)

(b)

(c)

(d)

(e)

(Hint. After each multiplication, reduce modulo 8157 before doing the next multiplication.)

(f)

(g)

(h)

1.18. Find all values of between and that are solutions of the following congruences. (Hint. If you can’t figure out a clever way to find the solution(s), you can just substitute each value and see which ones work.)

(a)

(b)

(c)

(d)

(e)

(f)

(g) and also . (Find all solutions modulo 35, that is, find the solutions satisfying .)

1.19. Suppose that and that . Prove that

1.20. Prove that if and are units modulo , then is a unit modulo .

1.21. Prove that is prime if and only if , where is Euler’s phi function.

1.22. Let .

(a) Suppose that is odd. What integer between and equals ?

(b) More generally, suppose that . What integer between and is equal to ?

1.23. Let be an odd integer and let be any integer. Prove that can never be a perfect square. (Hint. If a number is a perfect square, what are its possible values modulo 4?)

1.24.

(a) Find a single value that simultaneously solves the two congruences

(Hint. Note that every solution of the first congruence looks like for some . Substitute this into the second congruence and solve for ; then use that to get .)

(b) Find a single value that simultaneously solves the two congruences

(c) Find a single value that simultaneously solves the three congruences

(d) Prove that if , then the pair of congruences

has a solution for any choice of and . Also give an example to show that the condition is necessary.

1.25. Let , , and be positive integers (note that need not be prime). Prove that the following algorithm, which is a low-storage variant of the square-and-multiply algorithm described in Sect. 1.3.2, returns the value . (In Step 4 we use the notation to denote the greatest integer function, i.e., round down to the nearest integer.)

Input. Positive integers , , and .

  1. Set and .
  2. Loop while .
  3.  If , set .
  4.  Set and .
  5.  If , continue with loop at Step 2.
  6. Return the number , which equals .

1.26. Use the square-and-multiply algorithm described in Sect. 1.3.2, or the more efficient version in Exercise 1.25, to compute the following powers.

(a)

(b)

(c)

1.27. Consider the congruence .

(a) Prove that there is a solution if and only if divides .

(b) If there is a solution, prove that there are exactly distinct solutions modulo .

(Hint. Use the extended Euclidean algorithm (Theorem 1.11).)


Section 1.4: Prime Numbers, Unique Factorization, and Finite Fields

1.28. Let be a set of prime numbers, and let

Prove that is divisible by some prime not in the original set. Use this fact to deduce that there must be infinitely many prime numbers. (This proof of the infinitude of primes appears in Euclid’s Elements. Prime numbers have been studied for thousands of years.)

1.29. Without using the fact that every integer has a unique factorization into primes, prove that if and , then . (Hint. Use the fact that it is possible to find a solution to .)

1.30. Compute the following values:

(a)

(b)

(c) for each and

1.31. Let be a prime number. Prove that has the following properties.

(a) . (Thus resembles the logarithm function, since it converts multiplication into addition!)

(b) .

(c) If , then .

A function satisfying properties (a) and (b) is called a valuation.


Section 1.5: Powers and Primitive Roots in Finite Fields

1.32. For each of the following primes and numbers , compute in two ways: (i) Use the extended Euclidean algorithm. (ii) Use the fast power algorithm and Fermat’s little theorem. (See Example 1.27.)

(a) and .

(b) and .

(c) and .

1.33. Let be a prime and let be a prime that divides .

(a) Let and let . Prove that either or else has order . (Recall that the order of is the smallest such that in . Hint. Use Proposition 1.29.)

(b) Suppose that we want to find an element of of order . Using (a), we can randomly choose a value of and check whether satisfies . How likely are we to succeed? In other words, compute the value of the ratio

(Hint. Use Theorem 1.30.)

1.34. Recall that is called a primitive root modulo if the powers of give all nonzero elements of .

(a) For which of the following primes is 2 a primitive root modulo ?

  • (i)   (ii)   (iii)   (iv)

(b) For which of the following primes is 3 a primitive root modulo ?

  • (i)   (ii)   (iii)   (iv)

(c) Find a primitive root for each of the following primes.

  • (i)   (ii)   (iii)   (iv)

(d) Find all primitive roots modulo 11. Verify that there are exactly of them, as asserted in Remark 1.32.

(e) Write a computer program to check for primitive roots and use it to find all primitive roots modulo 229. Verify that there are exactly of them.

(f) Use your program from (e) to find all primes less than 100 for which 2 is a primitive root.

(g) Repeat the previous exercise to find all primes less than 100 for which 3 is a primitive root. Ditto to find the primes for which 4 is a primitive root.

1.35. Let be a prime such that is also prime. Suppose that is an integer satisfying

Prove that is a primitive root modulo .

1.36. This exercise begins the study of squares and square roots modulo .

(a) Let be an odd prime number and let be an integer with . Prove that either has two square roots modulo or else has no square roots modulo . In other words, prove that the congruence has either two solutions or no solutions in . (What happens for ? What happens if ?)

(b) For each of the following values of and , find all of the square roots of modulo .

  • (i)   (ii)
  • (iii)   (iv)

(c) How many square roots does 29 have modulo 35? Why doesn’t this contradict the assertion in (a)?

(d) Let be an odd prime and let be a primitive root modulo . Then any number is equal to some power of modulo , say . Prove that has a square root modulo if and only if is even.

1.37. Let be a prime and suppose that the congruence has a solution.

(a) Prove that for every exponent the congruence

X^2 \equiv b \pmod{p^e} \tag{1.14}

has a solution. (Hint. Use induction on . Build a solution modulo by suitably modifying a solution modulo .)

(b) Let be a solution to . Prove that in (a), we can find a solution to that also satisfies .

(c) Let and be two solutions as in (b). Prove that .

(d) Use Exercise 1.36 to deduce that the congruence (1.14) has either two solutions or no solutions modulo .

1.38. Compute the value of for every prime . Make a conjecture as to the possible values of when is prime and prove that your conjecture is correct.


Section 1.6: Cryptography by Hand

1.39. Write a 2–5 page paper on one of the following topics, including both cryptographic information and placing events in their historical context:

(a) Cryptography in the Arab world to the fifteenth century.

(b) European cryptography in the fifteenth and early sixteenth centuries.

(c) Cryptography and cryptanalysis in Elizabethan England.

(d) Cryptography and cryptanalysis in the nineteenth century.

(e) Cryptography and cryptanalysis during World War I.

(f) Cryptography and cryptanalysis during World War II.

(Most of these topics are too broad for a short term paper, so you should choose a particular aspect on which to concentrate.)

1.40. A homophonic cipher is a substitution cipher in which there may be more than one ciphertext symbol for each plaintext letter. Here is an example of a homophonic cipher, where the more common letters have several possible replacements (see Table in textbook for full cipher alphabet).

Decrypt the following message:

1.41. A transposition cipher is a cipher in which the letters of the plaintext remain the same, but their order is rearranged. Here is a simple example in which the message is encrypted in blocks of 25 letters at a time. Take the given 25 letters and arrange them in a 5-by-5 block by writing the message horizontally on the lines. For example, the first 25 letters of the message

Now is the time for all good men to come to the aid…

is written as

Now the ciphertext is formed by reading the letters down the columns, which gives the ciphertext NTMAO OHELD WEFLM ITOGE SIRON.

(a) Use this transposition cipher to encrypt the first 25 letters of the message:

Four score and seven years ago our fathers…

(b) The following message was encrypted using this transposition cipher. Decrypt it.

WNOOA HTUFN EHRHE NESUV ICEME

(c) There are many variations on this type of cipher. We can form the letters into a rectangle instead of a square, and we can use various patterns to place the letters into the rectangle and to read them back out. Try to decrypt the following ciphertext, in which the letters were placed horizontally into a rectangle of some size and then read off vertically by columns.

WHNCE STRHT TEOOH ALBAT DETET SADHE
LEELL QSFMU EEEAT VNLRI ATUDR HTEEA

(For convenience, we’ve written the ciphertext in 5-letter blocks, but that doesn’t necessarily mean that the rectangle has a side of length 5.)


Section 1.7: Symmetric Ciphers and Asymmetric Ciphers

1.42. Encode the following phrase (including capitalization, spacing and punctuation) into a string of bits using the ASCII encoding scheme given in Table 1.10.

Bad day, Dad.

1.43. Consider the affine cipher with key whose encryption and decryption functions are given by

where is the inverse of modulo .

(a) Let and let the key be . Encrypt the message . Decrypt the ciphertext .

(b) Assuming that is public knowledge, explain why the affine cipher is vulnerable to a known plaintext attack. (See Property 4 on page 38.) How many plaintext/ciphertext pairs are likely to be needed in order to recover the private key?

(c) Alice and Bob decide to use the prime for their affine cipher. The value of is public knowledge, and Eve intercepts the ciphertexts and and also manages to find out that the corresponding plaintexts are and . Determine the private key and then use it to encrypt the message .

(d) Suppose now that is not public knowledge. Is the affine cipher still vulnerable to a known plaintext attack? If so, how many plaintext/ciphertext pairs are likely to be needed in order to recover the private key?

1.44. Consider the Hill cipher defined by (1.11),

where , , and are column vectors of dimension , and is an -by- matrix.

(a) We use the vector Hill cipher with and the key

  • (i) Encrypt the message .
  • (ii) What is the matrix used for decryption?
  • (iii) Decrypt the message .

(b) Explain why the Hill cipher is vulnerable to a known plaintext attack.

(c) The following plaintext/ciphertext pairs were generated using a Hill cipher with the prime . Find the keys and .

(d) Explain how any simple substitution cipher of the alphabet can be thought of as a special case of a Hill cipher.

1.45. Let be a large integer and let . For each of the functions listed in (a)–(c), answer the following questions:

  • Is an encryption function?
  • If is an encryption function, what is its associated decryption function ?
  • If is not an encryption function, can you make it into an encryption function by using some smaller, yet reasonably large, set of keys?

(a)

(b)

(c)

1.46.

(a) Convert the 12-bit binary number into a decimal integer between and .

(b) Convert the decimal integer into a binary number.

(c) Convert the decimal integer into a binary number.

(d) Use exclusive or (XOR) to “add” the bit strings .

(e) Convert the decimal numbers 8734 and 5177 into binary numbers, combine them using XOR, and convert the result back into a decimal number.

1.47. Alice and Bob choose a key space containing keys. Eve builds a special-purpose computer that can check keys per second.

(a) How many days does it take Eve to check half of the keys in ?

(b) Alice and Bob replace their key space with a larger set containing different keys. How large should Alice and Bob choose in order to force Eve’s computer to spend 100 years checking half the keys? (Use the approximation that there are 365.25 days in a year.)

1.48. Explain why the cipher

defined by XOR of bit strings is not secure against a known plaintext attack. Demonstrate your attack by finding the private key used to encrypt the 16-bit ciphertext

if you know that the corresponding plaintext is

1.49. Alice and Bob create a symmetric cipher as follows. Their private key is a large integer and their messages (plaintexts) are -digit integers .

To encrypt a message, Alice computes to decimal places, throws away the part to the left of the decimal point, and keeps the remaining digits. Let be this -digit number. (For example, if and , then and .)

Alice encrypts a message as .

Since Bob knows , he can also find , and then he decrypts by computing .

(a) Alice and Bob choose the secret key and use it to encrypt 6-digit integers (i.e., ). Bob wants to send Alice the message . What is the ciphertext that he sends?

(b) Alice and Bob use the secret key and use it to encrypt 8-digit integers. Alice receives the ciphertext . What is the plaintext ?

(c) Show that the number used for encryption and decryption is given by the formula

where denotes the greatest integer that is less than or equal to .

(d) (Challenge Problem) If Eve steals a plaintext/ciphertext pair , then it is clear that she can recover the number since . If is large compared to , can she also recover the number ? This might be useful, for example, if Alice and Bob use some of the other digits of to encrypt subsequent messages.

1.50. Bob and Alice use a cryptosystem in which their private key is a (large) prime and their plaintexts and ciphertexts are integers. Bob encrypts a message by computing the product . Eve intercepts the following two ciphertexts:

Use the method described in Sect. 1.7.4 to find Bob and Alice’s private key.