Simple RSA key generation + Commutative Key
With RSA, initially the person picks two prime numbers. For example:
p=11 and q=3
In the following you can either manually add your own values, or generate random ones by pressing the button:
Next, the n value is calculated. Thus:
n = p x q = 11 x 3 = 33
Next PHI is calculated by:
PHI = (p-1)(q-1) = 20
The factors of PHI are 1, 2, 4, 5, 10 and 20. Next the public exponent e is
generated so that the greatest common divisor of e and PHI is 1 (e
is relatively prime with PHI). Thus, the smallest value for e is:
e = 3
The factors of e are 1 and 3, thus 1 is the highest common factor of
them. Thus n (33) and the e (3) values are the public keys. The
private key (d) is the inverse of e modulo PHI.
d=e^(-1) mod [(p-1)x(q-1)]
This can be calculated by using extended Euclidian algorithm, to give the
=7.
The encryption and decryption keys are then:
As a test you can manually put in p=11 and q=3, and get the keys of (n,e)=(33,3)
and (n,d)=(33,7).
The PARTY2 can be given the public keys of e and n, so that PARTY2
can encrypt the message with them. PARTY1, using d and n can then
decrypt the encrypted message.
For example, if the message value to decrypt is 4, then:
c = m^e mod n = 43 mod 33 = 31
Therefore, the encrypted message (c) is 31.
The encrypted message (c) is then decrypted by PARTY1 with:
m = c^d mod n = 317 mod 33 = 4
which is equal to the message value.
Encryption/Decryption:
Message: 123
Encrypt:
Decrypt:
|