(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:
- You know the drill: Test your code. Make sure it runs on the
UNIX machines. Make sure it works on large (e.g., 100-digit)
integers. Use any language you like, but don't use a built-in
primality function. Take input from the keyboard, write to
standard output.
Use
hwsubmit to turn in your code.
- You should use the Miller-Rabin algorithm from Section 7.4.
- There is a parameter s in the algorithm; this represents how
many witnesses you try. You can ask the user to enter s, or just
hardcode it. (I'd recommend s = 100.)
- We will test your code on large primes and on large composite
numbers (even Carmichael numbers).
(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:
- 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.
- Try odd numbers, starting with the number from part 1, until you
find a probable prime p.
- Repeat steps 1 and 2 to find a probable prime q.
- 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).
- Write N and e to one file, and N and d to another file.
- One program should decrypt a message:
- Ask the user to input a message.
- 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.)
- Encrypt K with the public key using RSA.
- Encrypt the message using DES and the key K.
- 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:
- Input an encrypted key and message, either from standard input or from a
file (whatever works with how you saved the encrypted message).
- Decrypt the key K with the private key using RSA.
- Decrypt the message using DES and the key K.
- 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.
(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.
(10 points) Stallings, Problem 12.2.