Main » 2011 » Март » 16 » Algorithm rsa
13:29
Algorithm rsa
All have heard about asymmetric cryptography, but I certainly do not all know what it is and what is it they eat.

Let's try to understand this as an example of the algorithm RSA.

The RSA algorithm is at the origins of cryptography was proposed by three researchers-mathematicians Ronald Rivet-Stom (R. Rivest), Adi Shamir (A. Shamir) and Leonard Adlmanom (LAdleman) in 1977-78, respectively.

Any asymmetric encryption requires a key pair, namely open and closed. Why should they?




The above is a scheme of interaction of objects in assimetrishnoy encryption system. Generator gives us a couple of key open ([Ea, N]) and closed ([Da, N]), is transmitted to the subscriber's public key which encrypts a message and sends the encrypted message (Ea (DATA)) receiver to decode the private key ([Da, N ]) and gets the original message.

The RSA algorithm is based on the unilateral use of encryption functions which have the property:
  • If x is known, then f (x) is relatively easy to calculate the
  • If y is known, then f (x) is practically impossible to calculate

The basis of a cryptographic system with RSA public key is put the task of multiplication and decomposition of primes in the factorization, which is computationally one-way task.

Algorithm for creating public and private keys


1. Choose 2 primes p and q.
2. Vychistlyaetsya their product N = p * q
3. Calculate the value of the Euler function f (p, q) = (p-1) * (q-1)
4. Selects a prime e is mutually acceptable to the f (p, q)
5. Selects a number d satisfying e * d mod f (p, q) = 1
6. Pair [e, N] - public key encryption
7. Pair [a, N] - private key encryption

And so, now is the interestnoe encryption and decryption

Rassmatiravat be the example of the word blog, but let us first, namely to create a key pair.

1. p = 3 q = 11
2. N = 33
3. F (p, q) = 20
4. D = 3
5. 7 * 3 mod 20 = 1, e = 7

Encrypt word


We get the digital equivalent of the word blog, I decided to get it using the calculation of their serial numbers in the alphabet of the digital equivalent of = 2 (B) 13 (A) 16 (O) 4 (D) 10 (I).

Encryption is performed in accordance with yi = xie mod N, where xi is the digital equivalent of the letter, the other values ??obtained above.

Y1 = 27 mod 33 = 128 mod 33 = 29
y2 = 137 mod 33 = 62748517 mod 33 = 7
y3 = 167 mod 33 = 268 435 456 mod 33 = 25
y4 = 47 mod 33 = 16384 mod 33 = 16
y5 = 107 mod 33 = 10000000 mod 33 = 10

And so we got the encrypted message Well now we have to decrypt it is not so difficult task when we know the private key)

decoding


Decryption is performed using the formula xi = yid mod N

After a bit of anguish with a calculator we get:

x1 = 293 mod 33 = 24389 mod 33 = 2
x2 = 73 mod 33 = 343 mod 33 = 13
x3 = 253 mod 33 = 15625 mod 33 = 16
x4 = 163 mod 33 = 4096 mod 33 = 4
x5 = 103 mod 1933 = 1000 mod 33 = 10

As can be seen if we compare xi c serial numbers of letters we get the word BLOG.

Hurrah!

Remember one thing Asymmetric encryption is designed to encrypt a small amount of data unnecessarily, it is very resource intensive.

Author LanG. The article was written for the Invite to Habre.
Views: 771 | Added by: w1zard | Rating: 0.0/0
Total comments: 0
Имя *:
Email *:
Код *: