## The RSA Algorithm

The following box displays the RSA algorithm. The receiver creates two keys:-
• The numbers N & E will be the public key to be used by a sender to encrypt a message.
• The numbers N & D will be the private key to be used by the receiver to decrypt the message.
Enter two distinct prime numbers (p & q):-

The product, N, of p and q is:-
N =
With each decreased by 1 their product P becomes:-
P =
Enter (optional) two numbers D & E:-
 E = (should not share a factor with P) D = (D*E should be 1 more than some multiple of P)

PUBLISH THE NUMBERS N and E

The sender now enters the message
(a number M less than N to be encoded and sent to the receiver):-
M =
The sender uses the encryption, C = M^E mod N, to yield the code C as:-
C =

You, as receiver, use the decryption, M = C^D mod N, to retrieve the message M:-
M =

Remarks:-
• All that you need to know in the way of mathematical jargon is:-
• x mod y means the remainder when x is divided by y.
• x^y means x raised to the power y.
• At present the code does not include any input validation. For example, there is no check that the two numbers that you enter at the beginning of the algorithm are prime and distinct.
• If the user changes the value of a field and clicks outside the field then all dependent values below the change are updated. [Note that this is achieved by chaining the functions invoked by the event handlers.]
• The engine code declares and initializes the variables of the model.
• The engine code can be extracted and run in a JavaScript workspace.
• You can extract the engine code and attach your own interface to it.
Exercise. Modify the interface to allow the message to be a string of letters of the alphabet. [Represent each letter of the alphabet by an integer from 1 to 26; then encrypt the letters separately.]

Exercise. Repeat the preceding exercise, but represent each block of two letters as an integer.

Further exploration of RSA:-