\ Prelab 10: RSA Key Generation

Prelab 10: RSA Key Generation

Reading

Random Numbers

In order to create a RSA ket, you first need to learn how to create a random number. To create a (pseudo) random integer in the range [0,n) you can use the Random class:

int randIndex, n; Random gen = new Random(); randIndex = gen.nextInt(n);

Random gen = new Random() creates a new random number generator gen. The code randIndex = gen.nextInt(n) assigns to randIndex a pseudorandom, uniformly distributed integer value between 0 (inclusive) and n (exclusive), drawn from the random number generator gen's sequence. Inclusive means that the integer value 0 can be generated, while exclusive means the integer value n cannot.

Problem 1: Write a subroutine RandBetween which returns a random integer between low and high inclusive:

public int RandBetween(int low, int high) // returns a random integer between low and high inclusive { }

For example,

randIndex = RandBetween(0,4);

will assign to randIndex either 0, 1, 2, 3 or 4 with equal probability.

Key Generation

In lecture, we learned about RSA and how to implement RSA key generation in Java using the fields and methods of the BigInteger class.

Problem 2: Write a Java method keyGenerate selects an n and calculates the values of k and d. Make two copies of your prelab code. Submit one copy to your Lab TA at the beginning of lab session.

In Lab 10 you will add your key generation code to an RSA demo applet and implement the RSA encryption and decryption subroutines.

Requirements

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

The Java API specification for the BigInteger class is found here:

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


Credit to Albert Meixner and Tammy Bailey for originally developing this assignment.