Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Test file: import java.math.BigInteger; public class RSATester { public static boolean test_2() { RSA rsaEncoder = new RSA(); rsaEncoder.GenerateKeys(265); String messageText = Programming is fun
Test file:
import java.math.BigInteger; public class RSATester { public static boolean test_2() { RSA rsaEncoder = new RSA(); rsaEncoder.GenerateKeys(265); String messageText = "Programming is fun :)"; // Secret message byte[] messageByteArray = messageText.getBytes(); // Convert the message to a byte array BigInteger messageBI = new BigInteger(messageByteArray); //Convert the byte array to a BigInteger BigInteger messageEncrypted = rsaEncoder.Encrypt(messageBI); // Encrypt the BigInteger number if (messageEncrypted == null) { return false; } System.out.println("The encrypted text: " + messageEncrypted); BigInteger messageDecrypted = rsaEncoder.Decrypt(messageEncrypted); //Decrypt BigInteger number if (messageDecrypted == null) { return false; } byte[] decryptedByteArray = messageDecrypted.toByteArray(); //Convert the decrypted number to a byte array String decryptedText = new String(decryptedByteArray); //Convert the byte array to a string System.out.println("The decrypted text: " + decryptedText); if (decryptedText.compareTo(messageText) != 0) { return false; } return true; } public static boolean test_1() { RSA rsaEncoder = new RSA(); rsaEncoder.GenerateKeys(265); BigInteger num = new BigInteger("136"); // Create a number BigInteger num_encrypted = rsaEncoder.Encrypt(num); // Encrypt it if (num_encrypted == null) { return false; } System.out.println("The encrypted text: " + num_encrypted); BigInteger num_decrypted = rsaEncoder.Decrypt(num_encrypted); // Decrypt it if (num_decrypted == null) { return false; } System.out.println("The decrypted text: " + num_decrypted); if (num.compareTo(num_decrypted) != 0) { return false; } return true; } public static void main(String[] args) { if (!test_1()) { System.out.println("Test #1 failed!"); } else { System.out.println("Test #1 passed!"); } System.out.println(""); if (!test_2()) { System.out.println("Test #2 failed!"); } else { System.out.println("Test #2 passed!"); } } }Create the Java class (RSA.java) with three methods for: 1. Generating public and private keys. Name this method GenerateKeys. 2. Encrypting a number using the public key. Name this method Encrvpt. 3. Decrypting a number using the private key. Name this method Decrypt. The method GenerateKeys should implement steps 1 to 5 from the Wikipedia article. In the first step, two random prime numbers (p and q) with a bit length that is supplied to the GenerateKeys method are generated. Then, their multiplication (n) is computed. Next, the totient of this product is calculated. The totient of n is calculated as follows: tot -lcm(p - 1,
Step 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