Assignment 8: RSA (first attempt)
Paul Hewitt
30 October 2013
Due date: Friday, 1 November
• In ipython run discrete.py and import the list SomePrimes from the
module some primes.py. Choose random values of p and q and com-
pute n = pq and φ = (p − 1)(q − 1). Choose a random value of a in the
range [1, n − 1], taking care that it is relatively prime to φ. If not then
choose another. Finally, use egcd() to find b so that ab ≡ 1 mod φ.
Your public key is the pair a, n. Keep everything else in your private
key.
• On the whiteboard write your email address and public key. Copy
down everyone else’s email address and public key. Put all of the above
information in a module rsa.py. The beginning of your module should
look like this:
from discrete import *
p = ...
q = ...
n = p*q
phi = (p-1)*(q-1)
a = ...
b = ...
RSA_keys = {
’Paul’: {’email’: ’[email protected]’,
’public’: (652875049889,10326145750289),},
...
}
1
• Choose a random prime to be your message; call it m. Encipher m three
different times, using the public keys for the three intrepid students to
your right. Email all three ciphertexts to all three students.
• Decipher all of the messages ciphered with your public key. You should
be able to check whether all this worked by checking whether the de-
ciphered message is prime. You should also be able to re-encrypt the
plaintext with the public keys for the other two receipients of your cor-
respondent and thereby reproduce the other two messages you received.
Send me your file rsa.py along with all of your correspondence: the plain-
text you selected; the three encryptions of it and sent; the three ciphertexts
you received; and the plaintext you deciphered.