crypto:RSA

topic

Use the code to run the decoding

import gmpy2
e = 17
p = 473398607161
q = 4511491
d = gmpy2.invert(e,(p-1)*(q-1))
print(d)

Summarize

RSA (Rivest-Shamir-Adleman) is an asymmetric encryption algorithm commonly used for data encryption and digital signatures . It is based on the mathematical problem that the product of two large prime numbers is difficult to factor.

Here are the basic steps for RSA encryption:

1. Choose two different large prime numbers p and q.
2. Calculate n = p * q, where n is the modulus of RSA.
3. Calculate the Euler function φ(n) = (p - 1) * (q - 1).
4. Choose an integer e such that 1 < e < φ(n), and e and φ(n) are relatively prime. e is called the public key index.
5. Calculate the modular inverse element d of e such that (d * e) % φ(n) = 1. d is called the private key index.
6. The public key is (n, e) and the private key is (n, d).
7. To encrypt plaintext m, use the public key encryption algorithm: c = (m^e) % n, where c is the ciphertext.
8. To decrypt ciphertext c, use the private key decryption algorithm: m = (c^d) % n, where m is the plaintext.

Guess you like

Origin blog.csdn.net/gsumall04/article/details/133363094