b2KIT

Public Key Cryptography Explainer

Interactive explainer of public key cryptography concepts: key generation, encryption, signing, and the math behind RSA.

Tested tool guide Tested browser tools Checked August 16, 2026

What Public Key Cryptography Explainer does and how it behaves

Public key cryptography works because of modular arithmetic, but the algebra hides behind large numbers. This tool makes it visible: it generates a key pair from two primes, then walks encryption and decryption step by step, and flips the same operations around to demonstrate digital signatures. Small, hand-computable values keep every intermediate number on screen. The surprise most people hit: the two keys are interchangeable partners. Encryption with one key is undone by the other, in either direction, and that reversibility is exactly what turns encryption into signing. Secrecy is one use; proving you wrote a message is another.

How the result is produced

1

Key generation

Key generation picks two distinct primes p and q. Their product n = p x q becomes the modulus both keys share, and (p-1)(q-1) is Euler's totient phi. The tool picks an exponent e coprime with phi, then derives d as the modular inverse of e modulo phi, meaning e x d leaves remainder 1 modulo phi. The public key is (n, e); the private key is (n, d).

2

The encrypt/decrypt and sign/verify round trip

Encryption raises the message m to the exponent e modulo n, giving ciphertext c = m^e mod n; decryption raises c to d, recovering m, because e x d is a multiple of phi plus 1 and the exponents cancel. Signing runs the same computation with the keys swapped: s = m^d mod n, and anyone verifies it by checking that s^e mod n equals m.

Good uses

  • A student working through a cryptography course or the original RSA paper who wants to watch a key pair get generated and a full encrypt/decrypt round trip run with concrete numbers, not formulas.
  • A developer writing documentation or explaining to colleagues why signing uses the private key and verification uses the public key; running both directions with the same pair makes the symmetry concrete.
  • Someone reviewing their own RSA code who needs a precise mental model of the operations involved: which value is exponentiated, under which modulus, and why e and d cancel each other.

Limits and checks

  • Toy sizes mean toy security. To keep the math legible, the examples use small primes, so every key pair the tool demonstrates is trivially factorable. A real RSA modulus is 2048 bits or larger; only at those sizes is factoring genuinely hard, which is the whole security claim.
  • It shows textbook RSA, not production RSA. The steps demonstrate m^e mod n without the padding real systems add (OAEP for encryption, PSS for signatures). Raw textbook RSA is deterministic and malleable, so the outputs are not what a library such as OpenSSL would produce for the same inputs.
  • A message must be smaller than the modulus. Only short values fit one block, and real traffic never runs through RSA directly: hybrid schemes encrypt a random symmetric key with RSA and carry the actual message under the symmetric cipher. Longer inputs cannot be fed through the same operation.

Common questions

Can I use the keys this tool generates for real encryption?

No. Any key pair whose generation you can watch step by step uses numbers small enough to reason about, and such a modulus is trivially factored. Use the tool to understand the math, then generate real keys with a trusted library at 2048 bits or larger, ideally via the browser's Web Crypto API, and never copy demo values into production code.

Is a digital signature just encryption with the private key?

For the textbook math this tool shows, yes: signing and verification are the same modular exponentiation as decryption and encryption, with the keys swapped, and that symmetry is why the trick works. Production systems add different padding for each operation and use them for different goals, secrecy versus authenticity, so the answer is mathematically yes and practically no.

References and verification

The behavioral notes were checked against the browser implementation. Standards and primary references below define the relevant format, formula, or platform behavior.

Related Tools