In lecture you learned everything you needed to implement RSA key generation in Java using the fields and methods of the BigInteger class. In your Prelab you wrote the Java code for the keyGenerate() subroutine. In lab today you will add your subroutine to the RSA demo applet code and implement the RSA encryption and decryption subroutines. Once your code is working, you will have an applet just like this:
Press the Generate RSA Keys button to compute public and private key pairs. Enter your plaintext message in the box indicated and press Encrypt. Your encrypted text is shown. Press the Decrypt button to decrypt the ciphertext. You can generate a new set of keys for the same message by pressing the Generate RSA Keys button again. Press Clear to clear all areas of text.
Open the file RSA.html with a text editor (DO NOT double click on the RSA.html file. Doing so will freeze Eclipse. ) and add your name, NetID and resources used. Save the file.
Open RSA.java. Look for the following:
You should type both your subroutines in the space between these comment lines. You do not need to modify any other code in the applet.
Type your prelab code for the keyGenerate subroutine.
The only thing left to do before you can compile is to add a subroutine to perform encryption and decryption. In lecture we discussed how one subroutine could be used to perform both encryption and decryption, as they both perform the same computation.
Recall that RSA encyption takes as input a numeric value for the plaintext message P and the public key pair (k,n). The numeric ciphertext message C is then computed via the equation
C = (Mk)%n
Similarly, RSA decryption takes as input a numeric value for the ciphertext message C and the private key pair (d,n) and decrypts the ciphertext via the equation
D = (Cd)%n
All the values used for encryption and decryption are of type
BigInteger. We can use the modPow method of the
BigInteger class to perform the above computations for us.
Specifically, given BigInteger values x, y and
z, the value of We can write a subroutine crypt to perform both encryption and
decryption as follows. The input parameters to crypt will be
three variables of type BigInteger. The first variable, say
M, represents the numeric text message. The second and third
variables, say pkey and modkey, represent the RSA key
pair for the desired operation - pkey being the unique public or
private key and modkey being the shared modulus key. The
crypt subroutine returns a value of type BigInteger,
which is computed using the modPow method.
Type your code for the crypt subroutine below the code you
just added for keyGenerate.
Run your applet and test it for various inputs. If everything runs as it
should -- that is, you can generate keys, enter a message, encrypt it and get
your original message back by decrypting -- move on to the next section and
export your project. http://www.duke.edu/~login/cps1/10_RSAEncryption/RSA.html
and view your applet (replace login with your acpub login). Submit the files RSA.java and RSA.html using assignment
name lab10. DON'T FORGET TO INCLUDE YOUR NAME AND LAB SECTION AT THE TOP
OF ALL OF YOUR FILES!
Test your applet! :
Link to your applet
<li> <a href = "http://www.duke.edu/~login/cps1/10_RSAEncryption/RSA.html">
Lab 10: RSA Encryption</a>
Submitting
Credit to Albert Meixner and Tammy Bailey for originally developing this assignment.