Project 2: RSA Cryptography


The goal of this project is to become familiar with the RSA encryption algorithm through programming. You may work individually or in pairs on this project.

Programming RSA

Write a program to implement the RSA algorithm for cryptography. (Refer to Sections 9.11 of your text for details of the algorithm.)

Set up:

  1. Choose two large primes, p and q. (There are a number of sites on-line where you can find large primes.)
  2. Compute n = p * q, and Φ = (p-1)(q-1).
  3. Select an integer e, with 1 < e < Φ , gcd(e, Φ) = 1.
  4. Compute the integer d, 1 < d < Φ such that ed ≡ 1 (mod Φ). The numbers e and d are called inverses (mod Φ).
  5. Make n and e public. (Post them as a pair (n, e) with your name on the wiki on Moodle. You should list the modulus first, then the exponent.

Encryption:

  1. Convert the message into numbers, using the ASCII representation for characters. (For example, in ASCII, A = 65, B = 66, ... , space = 32, period = 46. You may find an ASCII table online.)
  2. Obtain the public key (n, e) of who you want to send a message to. (You should choose yourself for testing purposes. Then try your instructor's.)
  3. Encipher each letter (now a number, say m) by computing c ≡ me (mod n). Remember, you don't want to directly compute the exponentiation. You should either program the method of repeated squaring, or look at what is offered through a library in whatever language you are using.

Decryption:

  1. When you receive a string of numbers, such as 1743 452 625, use your private key d to compute 1743d (mod n), 452d (mod n) and 625d (mod n). This n is from your public key.
  2. Take the results of these and translate back into letters, using the same scheme as above.

Testing:

On Moodle there will be a wiki that contains public keys, encrypted messages, and decrypted messages.
  1. Look up your instructor's public key from the wiki on Moodle.
  2. Encrypt a message using the instructor'r public key and post it on Moodle.
  3. Watch for the decrypted message and confirm whether it is correct or not.
Optional challenge:
  1. Look up the public key of a classmate/another group from the wiki on Moodle.
  2. Encrypt a message with this person's/group's public key and post it on Moodle, along with the name of the intended recipient.
  3. The intended recipient will be expected to post the decrypted message.

Implementation Notes

Submit

You should submit your well-documented code on Moodle. (You should follow documentation standards similar to those in the computer science courses.) If you incorporated code found on the Internet in your program, you must properly cite and acknowledge the authors.