Lesson 8 of 15
RSA Cryptosystem
RSA Cryptosystem
RSA (Rivest–Shamir–Adleman, 1977) is the most widely deployed public-key cryptosystem. Its security rests on the integer factorization problem — factoring large numbers is believed to be computationally infeasible.
Key Generation
- Choose two distinct primes and
- Compute (the modulus)
- Compute (Euler's totient)
- Choose coprime to (the public exponent; common choice: )
- Compute (the private exponent)
Public key: · Private key:
Encryption and Decryption
Why It Works
By Euler's theorem: , so:
Classic Example
, , :
Encrypt 42: Decrypt 2557:
Your Task
Implement:
rsa_keypair(p, q, e)→(n, e, d)rsa_encrypt(m, e, n)— returnsrsa_decrypt(c, d, n)— returns
Use Python's built-in pow(base, exp, mod) for efficient modular exponentiation.
Python runtime loading...
Loading...
Click "Run" to execute your code.