[Blockchain Course] Introduction to RSA Algorithm Basic Knowledge Courseware Collection

① Mutual prime relationship

If two positive integers have no common factors other than 1, we say that the two numbers are mutually prime.

Even if they are not prime numbers, they can form a coprime relationship. (8 is not a prime number, and 9 is not a prime number. But 8 and 9 are relatively prime.)

② Euler function

The number of positive integers that form a relatively prime relationship with n and are smaller than n is called the Euler function of n, denoted as φ(n).

1. Non-prime numbers:

The numbers that have a relatively prime relationship with 8 and are less than 8 are 1, 3, 5, and 7. There are 4 numbers in total, 1, 3, 5, and 7, which are called the Euler functions of 8, and are recorded as φ (8) = 4.

2. Prime numbers:

If n is a prime number, then φ(n)=n-1. (Those younger than yourself are mutually exclusive)

3.

If n can be decomposed into the product of two integers with a mutually prime relationship, then φ(n)=φ(p1p2)=φ(p1)φ(p2)

例:φ(15)=φ(3×5)=φ(3)×φ(5)=2×4=8

③Modular inversion element

If two positive integers a and n are relatively prime, we can definitely find the integer b such that (ab)mod n=1, that is, (ab)÷n remainder 1, or ab-1=kn, then b is the "module" of a Anti-element".

Two positive integers a and n are relatively prime. If b is the modular inverse element of a, then b+kn are both modular inverse elements of a.

 Key generation steps

1. Randomly select two unequal prime numbers p and q.

        Example: p=61 q=53.

2. Calculate the product n of p and q,

        n=pxq= 61×53 = 3233  

3. Calculate the Euler function φ(n).

         φ(3233) = φ(61)xφ(53)=60x52=3120

4. Randomly select an integer e

        e conforms to the range: (1) 1<e<φ(n)

                                (2) e and φ(n) are relatively prime

        e=17

5. Calculate the modular inverse element d of e with respect to φ(n).

        Because e=17, φ(n)=3120

        So the equation 17d-3120k=1

        Take a group of (d, k) = (2753,-15)


There are 6 samples now

Two random unequal prime numbers p=61, q=53.

The product of p and q n=3233

Euler function φ(n) φ(3233)=3120

Random integer e                   e=17

Modulo negative element d             d=2753

6. Encapsulate (product n, random integer e), that is, (n, e) into a public key

   Encapsulate (product n, modulo inverse element d), that is, (n, d) into a private key 


[Encryption function]: c=m^emod n, using the recipient’s public key (n,e)

[Decryption function]: m= cd mod n, use the receiver’s private key (n, d) to decrypt   

7. Encryption function c=m^e mod n, using public key (n, e)

        m is the information the sender wants to send, c is the information encrypted by the sender

        c=65^17mod3233=2790

8. Decryption function m= c^d mod n, using private key (n, d)

        The receiver receives the encrypted information c and decrypts it

        m=2790^2753 mod 3233= 65


example:

 

 

Guess you like

Origin blog.csdn.net/weixin_56537692/article/details/124061086