RSA algorithm brief
http://pajhome.org.uk/crypt/rsa/rsa.html
1. Key generation:
1.1 Generate two large numbers (prime numbers) P and Q. (the number is only the number of herself and 1) 1.2 n = p * q1.3 m = (p-1) * (q-1) 1.4 generation Smaller number E makes E and M
(Specially borrowed the primary school mathematics textbooks to find out: the concept of mutualism is actually related to the number, the definition of mutuality is: If the number of non-0 integers A, B is 1, then these two numbers Mutual
1.5 Generate D, make D * E% M = 1,% representatives to find the remainder.
At this time, the public key is E and N, the private key is D and N. As for P, Q, M is immediately discarded
2. Encryption process: The formula generated by ciphertext C is: c = p ^ E% N, that is, the P is removed by N, which can be seen in the public key, and the encryption is only involved in clear text and public. .
At this point, you can pass the secret text, so that it is also intercepted and not understand what is the original text.
3. Decryption process: The formula of the plain text (decryption) P after receiving the ciphertext C is: p = c ^ D% N, that is, C's D party divided by N, which can be seen only to the private key and dense Text.
So from the whole process, as long as you keep your private key, you can disconnect the ciphertext and public keys.
For example: this example is used as an example, which is convenient, and the small number is not safe.
1. Key generation:
1.1 p = 7, q = 191.2 n = p * q = 7 * 9 = 1331.3 m = (p-1) * (q-1) = (7-1) * (19-1) = 1081.4 generate smaller Number E, aligning E and 108, 2, 3, 4 are not pairs, 5 is minimal, so E = 51.5 generate D, make D * E% M = 1, D * 5% 108 = 1, D * 5 In addition to 108, it is 1, ... then calculates D = 65
At this public key E = 5, n = 133. Private key D = 65, n = 133. Key calculation is completed
2. Encryption process: The principle of RSA is that the encrypted information should be less than the smaller of P and Q, so in this example, we have to indicate that the encrypted number is less than 7. So we take 6 as an example
Encryption: c = p ^ E% N = 6 ^ 5% 133 = 7776% 133 = 62, then Cipheet is 62. Put 62 out.
(I think it should also pass the public key, I know that the corresponding is that private key when I receive it.
3. Decryption process: (I want the recipient to receive ciphertext and public key, find the corresponding private key)
Decryption: P = C ^ D% N = 62 ^ 65% 133 = 62 * 62 ^ 64% 133 After a better bursary, the remainder is 6, see (http://pajhome.org.uk/crypt/RSA/RSA .html),