You may wish to read an overview of RSA Public Key Cryptography.
To operate the demo:
We call (E, N) the Public Key and (D, N) the Private Key.
To start with, you might want to just leave the values of p and q as they are. The reason is that if p and q are too small, then N will be smaller than the values we are trying to encrypt or decrypt. When this happens, the system does not work properly.
Just as a check, it seems N should be greater than 40,000. This will allow all of the ASCII characters up to 128 to be encoded without problems.
The result will be the encrypted message shown in the Ciphertext field.
Your comments and suggestions are welcome: Richard Holowczak richard_holowczak@baruch.cuny.edu
A digital Key is a set of bits that are used to encrypt and decrypt messages. A form of cryptography called Public key cryptography uses two different keys:
Public and Private keys are generated in pairs so that only a specific pair of keys can perform the encryption and decryption functions. Any keys other than the specific pair will not work. A Public key is made known to everyone in the world. The matching private key is kept a secret by its owner.
In the following example, Alice would like to send
a message to Bill. She uses Bill's Public Key (which everyone
knows) to encrypt the message. The ciphertext is then sent
to Bill. Once he receives it, he can decrypt the ciphertext
using his Private key. Only Bill's Private key can be used
to decrypt.
RSA is a particular form of public key cryptography named
after its inventors: Ronald Rivest, Adi Shamir, and Leonard
Adleman in 1977. In RSA cryptography, a public and private
key pair are generated using the following steps:
Given a Message M, to encrypt into ciphertext C, we
use the following formula:
C = ME mod n
Our public key is (E, n)
Given a Ciphertext C, to decrypt into
plaintext message M we use the following formula:
M = CD mod n
Our private key is (D, n)
In practice, the message M is broken up into blocks (e.g., 64 bits at a time) and processed by the encryption algorithm.
The strength in RSA lies in the difficulty of factoring n. That is, guessing p and q given only the value of n. Currently this is a difficult problem in mathematics. A brute force approach, that is trying all potential p and q would take many thousands of years (depending on the size of the original p and q).
As the number of digits in p and q grow large, factoring becomes more difficult. So we consider the Key Size as directly related to the strength of the encryption. With n at 512 bits (154 digits), we consider this to be strong encryption. Total key size (E, n) or (D, n) would be 1024 bits.
Details of RSA cryptography and other cryptography
techniques can be found in the
RSA web site:
http://www.rsa.com
In particular, the 216 page FAQ contains a significant number of definitions of concepts related to security, cryptography and Electronic Commerce.
Java to the Rescue
I had originally attempted to provide a demo using several other tools such as MS Excel, JavaScript and others. However, I kept running into the problem that as the numbers got very large, these environments could not represent them accurately. I could have written something in C++ (which includes classes for arbitrary sized integers), however, I wanted something that would be easily portable and accessible over the web. Fortunately, I came across a special feature of Java called the bigInteger class described here.
This demo was written in the Java programming language. Specifically, it runs within a web browser as what is called a Java Applet. It was developed using the Java Development Kit version 1.1. The JDK 1.1 includes a special class called bigInteger that allows arbitrarily sized integers to be stored and operated upon. For example, the E, N and D are all represented as type bigInteger in the applet.
Generating the Public and Private Keys
The first part of the demo provides text boxes where the user can supply the values of p and q. Ideally p and q should be large prime numbers, however for the purposes of this demo, relatively small (less than 1000) values can be used. Presently simple checks are done on p and q to see if they are indeed prime.
Once p and q have been specified, clicking on the Calculate N button will generate the modulus n as p * q and will also calculate (p-1) * (q-1) which is used for other calculations later on.
The value of E is then automatically suggested as a number that is relatively prime to (p-1) * (q-1). This is accomplished by looping a variable from 2 to N and checking to see if the greatest common divisor (GCD) of this variable and (p-1) * (q-1) is one. Typically, the variable reaches 5 as its choice for E. Fortunately, the bigInteger class includes a method called gcd(bigInteger) that returns the GCD of two bigIntegers.
The value of D is then suggested by computing the mod-inverse of E. This gives a value for D such that E*D = 1 mod (p-1) * (q-1)
Once again, the bigInteger class comes to the rescue with a method called modInverse. This method is used to derive D given the value of E.
Encrypting a Message
At this point, we have now generated the necessary Public Key (E,n) and Private key (D,n). A message can be typed into the message field (labled M) and the Encrypt button can be clicked on.
Clicking on the Encrypt button causes the following steps to take place:
Decrypting a Ciphertext
Decrypting a message uses the RSA decryption algorithm blockD mod N to decrypt the encrypted message blocks. Clicking on the Decrypt button causes the following:
Acknowledgments
This program was inspired by this JavaScript example of RSA designed by Cary Sullivan and Rummy Makmur. (sullivca@ucs.orst.edu and makmur@flop.engr.orst.edu).
Even better, if the above links are not working, just do a search on Google for "RSA demo java applet"