RSA encryption demo

Source: Internet
Author: User

Select a pair of different, large enough prime numbers p and q.

Calculate n = PQ.

Calculate F (n) = (p-1) (q-1), and keep p and q confidential, so that no one knows.

Find a number e that interacts with F (n), and 1 <e <F (n ).

Calculate d so that De has 1 Mod f (n ). This formula can also be expressed as D? E-1 Mod f (N)
Here we need to explain that attention is the symbol in number theory that represents the same remainder. In the formula, the left side of the TRIM symbol must be the same as the right side of the symbol, that is, the result of the two-side modulo operation is the same. Obviously, no matter what value F (n) gets, the result of 1 Mod f (n) on the right of the symbol is equal to 1; the result of the modulo operation on the product of D and E on the left side of the symbol must be equal to 1. In this case, the value of D needs to be calculated so that the same equality can be established.

Public Key Ku = (E, n), private key Kr = (d, n ).

During encryption, the plaintext is first converted to an integer m from 0 to n-1. If the plain text is long, it can be divided into appropriate groups and then exchanged. If the ciphertext is set to C, the encryption process is C 127m ^ e mod n.

The decryption process is m Running C ^ d mod n.

From http://bank.hexun.com/2009-06-24/118958531.html

N = 33 = p * q = 3*11 T = (P-1) * (Q-1) = 2*10 = 20 E = 3 VaR E = 3, T = 20 , D;  For (D = 3; D & D <10000; D ++ ){   // Add d <10000 to avoid endless Loops      If (D * E % T = 1 ) {Console. Log ( 'D = % d' , D );  Break  ;}}  //  D = 7  //   //  N = 33  //  D = 7  // E = 3  //   //  C = m ^ d % N  //  M = C ^ e % N  Function RSA (A, K, M ){ //  A ^ K % m from http://wenku.baidu.com/view/27cea13743323968011c923b.html      VaR B = 1 ;  While (K> = 1 ){  If (K % 2 = 1) {B = A * B % M;} = A * A % M; k = Parseint (K/2 );}  Return  B ;} 

Http://www.ohdave.com/rsa/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.