This page provides use instructions and an example of use of my original, open source Rivest–Shamir–Adleman (RSA) public-key cryptosystem implemented in the Java. See the GitHub repository for the source code and documentation.


Note: There is no garuntee whatsoever of the security of this cryptosystem; this is only for fun and educational purposes.


Instructions


Setting Up the Cryptosystem

  1. Ensure the latest version of Java is installed on your machine.
  2. The following file structure is necessary for the cryptosystem to function. (It is sufficuent to simply clone the repository from my GitHub).
Matt's Improved RSA Utility
├── data
│   ├── MyCiphertext.txt
│   ├── MyD.txt
│   ├── MyE.txt
│   ├── MyM
│   ├── MyMessage.txt
│   ├── MyP.txt
│   ├── MyQ.txt
│   ├── TheirCiphertext.txt
│   ├── TheirE.txt
│   ├── TheirM.txt
│   ├── TheirMessage.txt
├── MattsImprovedRSAUtility.jar
  1. Acquire two unique primes of desired length. These two primes should be saved in MyP.txt and MyQ.txt, one in each text document.
  2. Navigate to the Matt's Improved RSA Utility directory with a command line, and run the following command:
java -jar MattsImprovedRSAUtility.jar
  1. This command will launch the utility within the Java Runtime Environment (JRE). You will be greeted by the following prompt:
Type E for Encryption, D for Decryption,
G to generate an M, E and a D, and X to exit.
  1. Type G to generate an \(E\) and an \(M\), and select an arbitrary integer \(n\). \(E\) and \(M\) are each integers (an "encryption exponent" and a "modulus") which you will send to your communication partner. These may be sent over an insecure line. They will automatically be stored in MyE.txt and MyM.txt, respectively, after running this command. Note: It is necessary to populate TheirE.txt and TheirM.txt with random numbers to perform this operation. You will overwrite them in the next step.

  2. Acquire your communication partner's \(E\) and \(M\). These should be stored in TheirE.txt and TheirM.txt, respectively.

  3. Type G again to generate \(D\), the decryption exponent (automatically stored in MyD.txt) corresponding to your communication partner's \(E\) and \(M\).

You are ready to begin communicating with your partner!

Encryption

  1. Type your plain-text message in MyMessage.txt.
  2. Run the E option at the utility prompt. This will populate MyCiphertext.txt with your encrypted message.
  3. This ciphertext message can then be sent to your partner over an insecure line.

Decryption

  1. Paste your partner's encrypted message in TheirCiphertext.txt.
  2. Run the D option at the utility prompt. This will populate TheirMessage.txt with their plain-text message.

An Illustration of Use


Suppose there are two parties, Wayne and Garth. Garth used the following primes for MyP.txt and MyQ.txt, and after choosing n = 8, receives the following integers for MyM.txt and MyE.txt:

After receiving Garth’s \(E\) and \(M\) (which, for the sake of simplicity, were identical to Wayne's) and saving them as TheirE.txt and TheirM.txt respectively, Wayne then generates the decryption exponent:

With the cryptosystem set up, Wayne wishes to encrypt the following message to Garth:

I see a little silhouetto of a man,

Scaramouche, Scaramouche, will you do the Fandango?

Thunderbolt and lightning,
Very, very frightening me.
(Galileo) Galileo.
(Galileo) Galileo,
Galileo Figaro
Magnifico-o-o-o-o.

After saving this message to MyMessage.txt and running the E command at the utility’s prompt, the following integers will be saved to Wayne’s MyCiphertext.txt:

3671251476783664
388014421150539437
139241812942305733
296211967931469283
363724763021325824
385337536563482711
208308641055171074
455123602977254591
208308641055171074
316831286352892003
487404379027281485
321716853402205210
445054343568014697
501077198262736464
148412892375125626
65165516989345880
192878817283726986
403472734457899295
118570028639235671
282245947752813862
161808896551838776
391218342992052048
299485656608194022
458629956861032581
5662119401589755
441708133827618386
110878501284377327
253952799117743544
495989761596281338
110528040224925385
286316856560588604
484986591279054801
342457866030976143
210834011866519079

This is Wayne's ciphertext. Wayne may now send Garth the contents of MyCiphertext.txt over an insecure line of communication. Garth now saves what he receives from Wayne as TheirCiphertext.txt and runs the decryption process with the D command at the utility’s prompt. Once this is completed, Garth now has a copy of the above message saved in TheirMessage.txt. Thus, the message has been communicated privately over an insecure line of communication.



Original code presented this site is under Creative Commons licensing which makes it possible to re-use this content for non-commercial purposes.