This project demonstrates an advanced RSA encryption algorithm implemented in Java. The code includes secure random key generation, exception handling, and encryption with decryption capabilities.
- Java Development Kit (JDK) 8 or higher
-
Compile the Code: Open a terminal or command prompt and navigate to the directory containing the
EnhancedRSA.java
file. Run the following command to compile the code:javac EnhancedRSA.java
- EnhancedRSA Class:
n
,e
, andd
are the RSA keys wheren
is the modulus,e
is the public exponent, andd
is the private exponent.- The constructor
EnhancedRSA(int bitLength)
initializes the keys with secure random prime numbers. convertToAscii(String input)
method converts the input string into its binary representation.calculate(String msg)
method performs the following steps:- Converts the message into a binary string.
- Converts the binary string into a BigInteger.
- Encrypts the integer message using the RSA algorithm and prints the ciphertext.
- Decrypts the ciphertext back to the original message and prints it.
Running the provided code with the message "Give me an A" will produce an output similar to the following:
Binary String: 010001110110100101110110011001010010000001101101011001010010000001100001011011100010000001000001
Integer Message: 8937694091556108062443830530
Ciphertext: <cipher text>
Decrypted Binary String: 010001110110100101110110011001010010000001101101011001010010000001100001011011100010000001000001
Decrypted Text: Give me an A
-
Changing the Bit Length: You can increase the bit length for more security by modifying the
bitLength
variable in themain
method:int bitLength = 1024; // Example for increased security
-
Changing the Message: Modify the string passed to the
calculate
method in themain
function:rsa.calculate("Your new message");
This project is licensed under the MIT License - see the LICENSE file for details.