Question
Write a java program that uses the BigInteger class to calculate/generate the keys needed for RSA encryption. p and q should each be at least
Write a java program that uses the BigInteger class to calculate/generate the keys needed for RSA encryption. p and q should each be at least 2048 bits in length. Initially though, you can test using a bit length of 100 or something like that. Your program should print the following values: d e p q n Generate p and q using the BigInteger probablePrime method (important: only create one Random object! And you can seed the Random constructor with a seed value if you want some initial stability in testing). Other BigInteger methods that you will use inclue modInverse and modPow. The notes suggest that the value e can be be a small odd int relatively prime to phi. However, message m raised to the power e where e is small may produce a value smaller than n which will make the mod ineffective. So, an alternate is to use probablePrime again to generate a larger e -- something of the same bit length as p or q...and then verify that the gcd of e and phi is 1. In addition, you program must demonstrate it's correctness by at a minimum printing the bit length of your encryption (i.e., the sum of the bit lengths for p and q) and also printing the results of the following lines of code: BigInteger m = new BigInteger("123456789"); BigInteger r = m.modPow(e, n); BigInteger m2 = r.modPow(d, n); m2 should come out the same as m. For fun, try different numeric values for m (from small to large) and see how the values for r and m2 change (or don't change). Extra credit (5 pts variable): Generate values for p and q that are as big as possible. Your program must also print the time in milliseconds it takes to run (use System.currentTimeMillis() to capture the start and end times). The bigger the values, the more extra credit. Note that the bigger the values, the longer it will take your program to run. If you want to make these values ridiculously LARGE (e.g., by allowing your program to run overnight, or for a day, or for several days), please do so -- your results will be interesting. For credit for the extra credit, please submit a copy of your output as a text file attachment.
10 pts. Write a java program that uses the BigInteger class to calculate/generate the keys needed for RSA encryption. p and q should each be at least 2048 bits in length. Initially though, you can test using a bit length of 100 or something like that. Your program should print the following values: 1. d 2. e 3. p 4. 9 5. n Generate p and q using the BigInteger probablePrime method (important: only create one Random object! And you can seed the Random constructor with a seed value if you want some initial stability in testing). Other BigInteger methods that you will use inclue modInverse and modPow. The notes suggest that the value e can be be a small odd int relatively prime to phi. However, message m raised to the power e where e is small may produce a value smaller than n which will make the mod ineffective. So, an alternate is to use probable Prime again to generate a larger e -- something of the same bit length as por q...and then verify that the god of e and phi is 1. In addition, you program must demonstrate it's correctness by at a minimum printing the bit length of your encryption (i.e., the sum of the bit lengths for p and q) and also printing the results of the following lines of code: BigInteger m = new BigInteger ("123456789"); BigInteger r = m.modPow(e, n); BigInteger m2 = r.modPow(d, n); m2 should come out the same as m. For fun, try different numeric values for m (from small to large) and see how the values for r and m2 change (or don't change). Extra credit (5 pts variable): Generate values for p and q that are as big as possible. Your program must also print the time in milliseconds it takes to run (use System.currentTimeMillis() to capture the start and end times). The bigger the values, the more extra credit. Note that the bigger the values, the longer it will take your program to run. If you want to make these values ridiculously LARGE (e.g., by allowing your program to run overnight, or for a day, or for several days), please do so -- your results will be interesting. For credit for the extra credit, please submit a copy of your output as a text file attachmentStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started