Course contentsShow
← Security
Lesson 143 of 3,0524. Asymmetric Cryptography and PKIFree lesson

RSA Encryption and Decryption Operations

How plaintext is transformed using modular exponentiation with public and private exponents, including worked examples.

RSA Encryption and Decryption Operations

You'll learn: How RSA transforms plaintext into ciphertext and back using modular exponentiation with public and private keys.

The Core Idea

RSA encryption and decryption both rely on modular exponentiation—raising numbers to powers and taking the remainder after division. The beauty is that encryption uses one exponent (the public key), and decryption uses a different exponent (the private key), yet they mathematically undo each other.

Encryption transforms your plaintext message M into ciphertext C:

C = M^e mod n
  • e is the public exponent (typically 65537)
  • n is the modulus (product of two large primes)
  • M must be smaller than n

Decryption transforms ciphertext back to plaintext:

M = C^d mod n
  • d is the private exponent (kept secret)

Worked Example

Let's use small numbers (real RSA uses hundreds of digits):

  • Public key: e = 3, n = 33
  • Private key: d = 7, n = 33
  • Message: M = 4

Encrypting:

C = 4^3 mod 33 = 64 mod 33 = 31

Decrypting:

M = 31^7 mod 33
  = 27,512,614,111 mod 33 = 4

We got our message back! The mathematical relationship between e, d, and the prime factors ensures this works perfectly.

Why It Works

The private exponent d is specifically calculated so that (M^e)^d ≡ M (mod n) for any message M. This mathematical property—based on Euler's theorem and the careful selection of primes—is what makes RSA secure yet reversible.

Key Takeaway: RSA encryption raises plaintext to the public exponent mod n, while decryption raises ciphertext to the private exponent mod n—two operations that mathematically reverse each other through modular exponentiation.