RSA Algorithm
RSA Algorithm
RSA is a cryptosystem for public-key encryption, and is widely used for securing sensitive data. It uses two different keys, one public and one private key. The Private key is kept in secret whereas Public key is shared with everyone. It provides a method of assuring the confidentiality of data. RSA is rather slow so it’s hardly used to encrypt data, more frequently it is used to encrypt and pass around symmetric keys which can actually deal with encryption at a faster speed.
Below is the sample on how the data is encrypted and decrypted with RSA.
Four Steps are required:
- Generate Public Key
- Generate Private Key
- Encrypt Data with Public Key
- Decrypt Data with Private Key
Generate Public Key:
- Select 2 prime numbers P & Q. Let’s say P = 53, Q = 59.
- Public Key(p)
PQ i.e 53 * 59 = 3127
- We also need a small exponent ‘n’, this n must be
a). Be an integer
b). Not be a factor of p
c). 1<n<??(p), in this example n = 3 Our public key is made up of p & n, i.e 3127 & 3
Generate Private Key:
- We need to calculate ??(p)
??(p) = (P-1) (Q-1) ??(p) = (53-1) (59-1) ??(p) = 3016
- Now for calculating private key say d
d = (2(??(p))+1)/n
d = 2011
(After putting all the value from above)Private key d = 2011
Encrypt Data with Public Key:
Till now we have Public Key and Private Key, in this scenario Public Key is made up of p & n, i.e 3127 & 3. Our Private Key is d, i.e 2011.
Let’s encrypt ‘EG’. Convert the letters to number E= 5 and G = 7.Encrypt = 57?? mod 3127, here n = 3, so the result will be 700
Decrypt Data with Private Key:
Till now we have c = Encrypted Data n = Private key p = Public Key
Decrypt = c? mod p,
Decrypt = 700? mod 3127,
here n = 2011
After calculation decrypt = 57.
Now convert the number to their respective letters, i.e 5 = E, and 7 = G, So we have our result i.e EG.