Premium experiment • modular cryptography

COMPUTER SCIENCE & TECHNOLOGY • COMPUTING

RSA Cryptography Lab

Build a tiny educational RSA key pair, encrypt an integer, decrypt it, and inspect the modular arithmetic that makes the round trip work.

● MODULAR ARITHMETICRSA Cryptography
Modulus n
φ(n)
Private exponent d
Ciphertext c

Reasoning inspector

live internal state
Prime p—
Prime q—
Modulus n—
φ(n)—
Public exponent e—
Private exponent d—
Message m—
Ciphertext c—
Recovered message—
Encrypt exponent steps—

Inspect textbook RSA safely

The deliberately tiny keys make every arithmetic step visible. They are for learning only, not security, and the simulator explicitly documents the missing protections used by real RSA systems.

LEARN WITH THE SIMULATION

Understand RSA Cryptography Lab by experimenting.

START HERE

RSA connects number theory with public-key cryptography through modular exponentiation. This educational laboratory deliberately uses tiny prime numbers so every important value can be inspected: the modulus n, Euler totient φ(n), public exponent e, private exponent d, ciphertext, recovered message and the square-and-multiply exponentiation trace. The small keys make the mathematics transparent precisely because they are not secure enough for real cryptographic use.

BUILD THE IDEA

What you should understand first

  • Build an RSA modulus n = pq and Euler totient φ(n) = (p−1)(q−1) from two distinct primes.
  • Explain why a valid public exponent e must be coprime with φ(n).
  • Interpret d as the modular inverse satisfying ed ≡ 1 mod φ(n).
  • Follow modular exponentiation as repeated squaring and reduction rather than trying to calculate enormous ordinary powers.

TRY IT YOURSELF

Why does changing the public exponent force the private exponent to change?

  1. Choose two distinct primes and record n and φ(n).
  2. Select one valid public exponent and record the private exponent d.
  3. Change only e while keeping p, q and the message fixed, then inspect the new d.
  4. Verify that e·d mod φ(n) returns 1 in each valid case and that decrypting recovers the original message.
Read the visual:

The private exponent is not an independent secret number chosen arbitrarily. It is determined by the modular-inverse relation with e under modulus φ(n), so changing e changes the inverse that makes the RSA round trip work.

WHY IT WORKS 01

The public and private exponents are linked by modular inversion

Once p and q are chosen, the modulus n and totient φ(n) are fixed. The public exponent e must have gcd(e,φ)=1 so it has a multiplicative inverse modulo φ. That inverse is d. The equation ed = 1 + kφ for some integer k is the structural reason the exponents cooperate during encryption and decryption.

WHY IT WORKS 02

Modular exponentiation avoids gigantic intermediate powers

Even tiny RSA exponents would become inefficient if software first computed m^e as an ordinary integer and reduced only at the end. Square-and-multiply repeatedly squares the current base, multiplies only when a binary exponent bit is set and reduces modulo n at every stage. The result is exact while intermediate values remain bounded by the modulus.

WHY IT WORKS 03

Why this lab is intentionally insecure

Security would make the arithmetic impossible to inspect by eye. Real RSA commonly uses moduli thousands of bits long, while this simulator uses small primes so learners can verify φ(n), d and ciphertext values directly. That visibility is pedagogically useful, but the same small key size makes factoring immediate and therefore unsuitable for protecting any real information.

DO NOT MIX THESE UP

Common misconception

Textbook RSA is not secure encryption by itself. Tiny primes are trivial to factor, and production RSA requires large random primes, secure padding, robust key generation, side-channel-resistant implementation and carefully defined message encodings. The difficulty assumption is about factoring appropriately large moduli, not about the arithmetic being mysterious.

PRACTICE CHALLENGE

Can you predict whether a candidate public exponent is valid before trying it?

  • Choose p and q and compute or inspect φ(n).
  • For each available e, reason about whether gcd(e,φ(n)) equals 1.
  • Select valid exponents and verify that a private inverse d appears.
  • Explain why an exponent sharing a factor with φ(n) cannot have a modular inverse.
Reveal the reasoning

An inverse d exists exactly when e and φ(n) are coprime. If they share a factor greater than one, every product ed remains divisible by that factor modulo φ(n), so it can never be congruent to 1. Coprimality is therefore a mathematical requirement for the textbook key relation.

MODEL BOUNDARIES

What this simulation assumes

Every simulation simplifies reality or a mathematical system. These are the assumptions and limits to keep in mind while interpreting the results.

Model assumptions

  • The simulator uses two distinct small prime integers and textbook RSA arithmetic on a single integer message.
  • The public exponent must be greater than one, smaller than φ(n) and coprime with φ(n).
  • All modular arithmetic is exact using JavaScript BigInt for the supported small educational values.

Model limitations

  • The key sizes are intentionally tiny and cryptographically insecure; the simulator must not be used to protect real data.
  • Secure padding schemes, key generation randomness, side-channel resistance, signatures and production key formats are outside this model.

CONNECT IT

Where this matters

  • Public-key cryptography education
  • Modular arithmetic and number-theory instruction
  • Foundations for RSA encryption and signatures
  • Understanding why secure implementations require more than the textbook equations

WORDS THAT MATTER

Key vocabulary

Modulus
Composite integer n = pq shared by the public and private RSA operations.
Euler totient
For distinct primes p and q, φ(n) = (p−1)(q−1), the modulus used for the exponent-inverse relation in this teaching model.
Public exponent
Integer e chosen coprime with φ(n) and published with n.
Private exponent
Modular inverse d satisfying ed ≡ 1 mod φ(n).
Modular inverse
Number that multiplies another number to give 1 under a specified modulus.
Square-and-multiply
Efficient modular-exponentiation method that processes exponent bits while reducing modulo n at each step.