Skip Navigation Links
Home
News & Projects
Resources
Press Cut-Outs
About
Links
PhotoBlog

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:

 

p

q

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

Bob

n

PHI

e



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.

Bob

d

The encryption and decryption keys are then:

 

Encryption Key n,e)

Decryption Key (n,d)

 

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:

Commutative RSA key generation

RSA is commutative for keys with common n. First Alice generates its keys, then passes n, p and q to Bob. Exponent e is kept private. Thus, aim of the system is different than RSA. In commutative encryption the goal is to be able to encrypt and decrypt any plaintext in an arbitrary order. Since Bob knows n, p and q, the only things needed to run the protocols are Bob's e and d donated here by eB and dB. First Bob calculates PHI form the values provided by Alice:

p= 
q=
PHI=(p-1)(q-1)=

Then either eB or dB is generated, and the other exponent is calculated. In RSA it does not matted wheather e or d is generated first, however, for simplicyty of presentation e is usually selected first. This exponent is randomly choosen. It needs to be smaller than PHI, and relatively prime to it.

 

eB

Next, the d value is calculated. Thus:

d=e^(-1) mod [(p-1)x(q-1)]

This can be calculated by using extended Euclidian algorithm.

Bob

d

The encryption and decryption keys are then:

 

Bob's Encryption Key (n,eB)

Bob's Decryption Key (n,dB)

 

Now Alice and Bob can encrypt a plaintex that can be later decrypted in an arbitraty order. Encryption is performed just like in case of normal RSA

c = m^e mod n

This also applies to the decryption:

m = c^d mod n

In this protocol both parties keep their keys secret. They share n, p and q, but there is no public key or a private key. There are for keys Alice's encryption and decryption keys, as well as Bob's encryption and decryption keys.

Keys are commutative if a ciphertext created from a plaintext enrypted using two keys KA and KB is equal to a ciphertext created from the same plaintext encrypted using the same keys KA and KB in the different order.

Message: 123

Encrypted using Alice's key:

Encrypted using Bob's key:

The two cyphertext are different, since Bob's and Alice's keys are different.

Plaintext encrypted by Alice and then Bob  

Plaintext encrypted by Bob   and then Alice

Two ciphertexts are equal, this proves commutativity of encryption.

Ciphertext decrypted by Alice and then Bob  

Ciphertext decrypted by Bob   and then Alice

Copyright © 2008 WhiteboardIT (IT Training & Consultancy). All Rights Reserved.
Please, help me support
Chest, Heart & Stroke
Scotland

Please Donate!