RSA encryption and decryption

RSA encryption and decryption:


RSA algorithm is very simple, summarized as follows: 
To find two primes p and q 
Take n = p * q 
Take t = (p-1) * (q-1) 
Take any of a number e, required to satisfy e
Get d * e% t == 1 

This eventually get three numbers: nde 

Set message number M (M
Set c = (M ** d)% n to get the encrypted message c 
Set m = (c ** e)% n then m == M, c to complete the decryption. 
Note: ** said Power of above two equations in the d and e interchangeable. 

In symmetric encryption: 
nd two numbers constitute a public key, you can tell other people; 
ne two numbers constitute the private key, e their own reservations, that no one knows. 
Send the information to others using e encryption, as long as people can use d unlock information is to prove that you sent form the signature mechanism. 
When someone sends information encrypted using the d, e, so you can only have its decryption. 

rsa security is for a large number n, there is no effective method can be decomposed to nd in the case of the known lack of access to e; the same in the case of known ne can not obtain d.

Or, rsa security is for a large number n, there is no effective way to be decomposed into p and q. 

<2> Practice 

Next we come to a practice and see the actual operation: 
To find two prime numbers: 
p = 47 
q = 59 
So 
n = p * q = 2773 
t = (p-1) * (q-1) = 2668 
Take e = 63, satisfy e
C: \ Temp> perl-e "foreach $ i (1 .. 9999) (print ($ i), last if $ i * 63% 2668 == 1)" 
847 
That is d = 847 

Finally we get the key 
n = 2773 
d = 847 
e = 63 

Message M = 244 we take a look 

Encryption: 
c = M ** d% n = 244 ** 847% 2773 
Computation of large numbers with perl to count: 
C: \ Temp> perl-Mbigint-e "print 244 ** 847% 2773" 
465 
D on M that is encrypted with access to encrypted information, c = 465 

Decryption: 
We can use e to the c of the encrypted decrypt, restore, M: 
m = c ** e% n = 465 ** 63% 2773: 
C: \ Temp> perl-Mbigint-e "print 465 ** 63% 2773" 
244 
The use of e on c decrypted get m = 244, the M value and equal to the original information.

0 comments:

Post a Comment