If you are a student of computer science and plan to take a course related to data security, then this article will be of particular interest of yours; because sooner or later you will have to implement RSA either in its trivial or more sophisticated form. Before I present the code of its implementation let me propound how UI of this implementation has been designed.

To run the application, of course you need Java Runtime installed on your machine (complete SDK is recommended), as well as PATH variables should also be set. Now when you see the following window, you can start clicking on the buttons on the left hand side of the window from top to bottom. The program will perform the following tasks:

Create p: The program will create a random prime number of 512 bits, almost 150 digits.

Create q: The program will create another random prime number of the same size as p.

Encrypt: The program will encrypt the number produced by OAEP routine.

Decrypt: For verification that Encryption and Decryption routines are inverse of each other and that cipher text can be converted back to plain text, you can click on Decrypt button and you’ll see a congratulations message (hopefully, if everything goes alright).

Following is the window that you will see when you’ll run the java application.

General Formulas of RSA:

The first step of RSA implementation is its Key Generation, following are the steps:

Encryption and Decryption formulas are just sweet hearts; let’s have P as plaintext and C as ciphertext, and then the formulas will be as follows:

Now let’s take a look at the application, what does it do when we follow all the above given steps:

Up till that step your encryption is done, now to verify that encryption and decryption work inversely we need to click Decrypt button and get the following screen.

Okay, now I know what you guys want to say, I’ll just shut up and give you the source code, which is as follows, enjoy programming and have a great rest of the day 🙂

Beats me!
I could go back and study and answer your question, but frankly speaking I’m crazy busy these days, therefore, I encourage you to put some of your own effort and find out. Perhaps the application that is creating cipher code could pass P1Length as a parameter to the other application which is deciphering. Lastly, OAEP is not an essential part of RSA, you can skip OAEP and still implement RSA. Good luck!