Assignment 6

Due Tuesday, July 31, in class

Note: Don't forget to do Assignment 5, Problem 1, due Friday, July 27.
Problem 1 is due Friday, August 3.
Problem 2 is due Friday, August 10.

Recommended reading:

Don't forget: the midterm is on Tuesday, July 31.

  1. (due Friday, 8/3) (20 points) Write a program that takes an integer as input and outputs "prime" if the integer is probably prime and "composite" if the integer is definitely composite.

    Notes:

  2. (due Friday, 8/10) (50 points) Implement RSA.

    Notes:

    • You'll need programs to do several things. These can all be done in one program (prompt the user for a selection, or use the command line), or you can have a collection of programs. Whatever's easier.
    • One program must generate a public/private key pair. You should:
      1. Get a large number; you could call a PRNG, ask the user to type a number, ask the user to type gibberish and hash it; whatever you like. The number should be at least 50 digits long.
      2. Try odd numbers, starting with the number from part 1, until you find a probable prime p.
      3. Repeat steps 1 and 2 to find a probable prime q.
      4. Let N = pq, choose a value of e (either try the smallest e that's relatively prime to phi(N), or generate random e's until one works; this doesn't need to be done with a secure random number generator), and solve for d so that ed = 1 mod phi(N).
      5. Write N and e to one file, and N and d to another file.
    • One program should decrypt a message:
      1. Ask the user to input a message.
      2. Generate a key K. (Technically, this should be done with a secure random number generator. If you can figure out how, you can use one, but don't worry about it.)
      3. Encrypt K with the public key using RSA.
      4. Encrypt the message using DES and the key K.
      5. Save the key and encrypted message to a file, or write them to the screen in some ASCII-readable form.
    • Finally, one program should decrypt a message:
      1. Input an encrypted key and message, either from standard input or from a file (whatever works with how you saved the encrypted message).
      2. Decrypt the key K with the private key using RSA.
      3. Decrypt the message using DES and the key K.
      4. Output the decrypted message to the screen.
    • You can hardcode the file-names for the public key, private key, and encrypted key and message, or you can prompt the user. You can store the encrypted key and message in one file or two. Whatever's easiest for you; I want to minimize the amount of time you spend getting file I/O working.
    • Note that you will be using nearly every program you've written this quarter. If you did poorly on an earlier assignment and need a working component, talk to me or Ian, or ask for help on the list.
    • Yes, you're storing the private key in the clear. You can encrypt it with a passphrase if you want for extra credit.
    • This is the last programming assignment for the quarter. Good luck.
    • If you have questions, post them to the list. If you have answers, post them to the list. I appreciate people who post good questions, and people who give correct (or mostly-correct) answers.

    Problems 3-4 should be submitted in class, July 31, on paper.

  3. (15 points) Stallings, Problem 7.7.
    Note: this problem was originally assigned as extra credit in Assignment 1. If you turned it in before, you don't need to do it again; I'll use your old score. If you do it again, I'll take the higher score. Note that can you can mix and match: for example, if you did a, b, c correctly last time, you can just turn in d this time.
  4. (10 points) Stallings, Problem 12.2.

Course home page