# Prelab 7: RSA Key Generation

In Lecture 16 we learned everything we needed to implement RSA key generation in Java using the fields and methods of the BigInteger class. Your prelab assignment is to write a Java subroutine to do this. In Lab 7 you will add your key generation code to an RSA demo applet and implement the RSA encryption and decryption subroutines.

Make two copies of your prelab code. One copy will be submitted at the beginning of lab session.

## Requirements

Follow these instructions carefully, as the RSA applet will expect your subroutine to have a particular name and assign values to the specified fields.

• There are no input parameters.

• The return type of your subroutine should be void, that is, your subroutine does not return a value when called. The reason for this is as follows: the public and private keys will be declared as fields or attributes in the java code. Their values will be computed and assigned by your subroutine.

• The variable names for the public and private keys are k, d and n and are of type BigInteger. The pair (k,n) corresponds to the public RSA key and the pair (d,n) corresponds to the private RSA key.

• You must declare any variables other than the aforementioned that you require. Declaring a variable means that you must explicitly specify a name and a type before you can use it in your program.

• In Lecture we discussed the probablePrime method that can be used to generate a prime BigInteger with specified bit length. There are two subroutines provided for you in the RSA code that you should use to specify bit lengths. They are bigBit() and smallBit(), and they return a random bit size within a prespecified range such that the values returned by bigBit() are always larger than those returned by smallBit(). For example, if we want to assign a "large" prime to a BigInteger named p, we could use the statement

p = BigInteger.probablePrime( bigBit(), rng );

To assign a "small" prime to a BigInteger named s, we would use the statement

s = BigInteger.probablePrime( smallBit(), rng );

Note that the above statements are only valid when p, s and rng have already been declared.

• The purpose of the keyGenerate subroutine is to compute the values of the public and private RSA keys. As such, your subroutine must assign values to k, d and n.

The Java API specification for the BigInteger class is found here, if you are interested:

http://java.sun.com/j2se/1.4.2/docs/api/java/math/BigInteger.html