🔐

Cryptography

Cryptography is the mathematics that keeps messages secret, proves who sent them, and lets strangers agree on a shared secret in full view of an eavesdropper. This hub gathers the site's cryptography and distributed-systems simulations into one guided starting point, from the 2,000-year-old Caesar cipher to the RSA and elliptic-curve mathematics that secure the modern internet, plus the hashing and consensus tricks that hold a blockchain together.

10+ simulations Canvas 2D · Interactive Step-Through Protocols

Simulations in this Topic

10 simulations across Cryptography and Distributed Systems

🏛️ ★☆☆☆ Easy
Caesar & Vigenère Ciphers
Encrypt and decrypt messages with classical substitution ciphers, then watch a frequency-analysis attack find the most likely key automatically.
Cryptography
🤝 ★★☆☆ Moderate
Diffie-Hellman Key Exchange
Two parties establish a shared secret over an insecure channel — the colour-mixing analogy makes the discrete logarithm problem intuitive.
Cryptography
🔑 ★★☆☆ Moderate
RSA Key Exchange
Step through RSA: choose two primes, compute n and φ(n), find e and d, then watch a message encrypted and decrypted with the public/private keypair.
Cryptography
📈 ★★★☆ Advanced
Elliptic Curve Cryptography
Visualise point addition on an elliptic curve over a real field, and see how scalar multiplication generates a keypair that is hard to reverse.
Cryptography
#️⃣ ★★★☆ Advanced
Hash Functions — Avalanche & Collisions
Flip one input bit and watch roughly half the output bits change — the avalanche effect — and see the birthday bound make collisions likelier than intuition suggests.
Cryptography
🌳 ★★★☆ Advanced
Merkle Tree — Hash Trees & Proofs
Build a Merkle tree by hashing data blocks pairwise up to a single root, change a leaf and watch the root change, and verify a block with a logarithmic proof.
Cryptography
⛓️ ★★★★ Expert
Blockchain Consensus
Proof-of-Work mining and longest-chain consensus: miners race to beat the difficulty target, forks resolve, and a 51% attacker's success probability is shown live.
Cryptography
💻 ★★★☆ Advanced
Distributed Consensus
Explore the Raft consensus algorithm, the CAP theorem and Byzantine fault tolerance — the agreement problems that underpin secure distributed systems.
Distributed Systems
💍 ★★★☆ Advanced
Consistent Hashing — The Hash Ring
Map keys and servers onto a hash ring so adding or removing a node only remaps a small fraction of keys — the technique behind distributed caches and DHTs.
Distributed Systems
🌸 ★★★☆ Advanced
Bloom Filter — Probabilistic Set Membership
A Bloom filter tests set membership with k hash functions over a bit array — no false negatives, tunable false positives, used to pre-check hashes at scale.
Distributed Systems

Suggested Learning Path

Five simulations, in the order we recommend exploring them

  1. 1
    1. Caesar & Vigenère Ciphers

    Start with the oldest ciphers in the book, then watch frequency analysis break them in seconds — the reason classical substitution ciphers were retired.

  2. 2
    2. Diffie-Hellman Key Exchange

    See how two strangers can agree on a shared secret over a channel an eavesdropper can watch, using the colour-mixing analogy for the discrete logarithm problem.

  3. 3
    3. RSA Key Exchange

    Move to public-key cryptography proper — generate a real keypair from two primes and watch encryption and decryption run with it.

  4. 4
    4. Elliptic Curve Cryptography

    See the modern, more efficient alternative to RSA that secures most HTTPS connections and cryptocurrency wallets today.

  5. 5
    5. Merkle Tree — Hash Trees & Proofs

    Finish with the hashing structure that lets a blockchain prove a transaction is included in a block without downloading the whole chain.

Related Articles

The theory and maths behind the simulations above

How Encryption Works — From Caesar Cipher to RSA
A guided tour from substitution ciphers through symmetric encryption to the public-key mathematics behind RSA.
RSA Encryption: The Mathematics of Large Primes
Euler's totient, modular exponentiation, and why factoring the product of two large primes is computationally hard.
How Diffie-Hellman Key Exchange Works — HTTPS Explained
How two parties derive a shared secret over an insecure channel, and how it fits into every HTTPS handshake.
Blockchain & Bitcoin: The Mathematics
The elliptic-curve signatures, hash puzzles and Merkle trees that make a blockchain tamper-evident.
How a Blockchain Works — From SHA-256 to Bitcoin
A block-by-block walkthrough of hashing, mining and consensus in a Bitcoin-style blockchain.
Consistent Hashing — Distributed Load Balancing with Virtual Nodes
How consistent hashing lets distributed caches and databases scale without reshuffling every key on every server change.

About the Cryptography Topic

From Caesar to consensus — a complete map of the topic

Cryptography is the mathematics of keeping secrets, proving identity, and reaching agreement in the presence of an adversary who can see (and sometimes tamper with) every message. It is one of the oldest applied mathematical disciplines — Julius Caesar reportedly shifted his military messages by three letters — and one of the most consequential: every HTTPS connection, every password database, and every cryptocurrency transaction depends on the ideas gathered in this hub. Each simulation here is a real, runnable implementation of the protocol it demonstrates, not an illustration, so the numbers you see on screen are the numbers the algorithm actually produces.

The Caesar and Vigenère cipher simulation is the natural starting point: a substitution cipher shifts or scrambles the alphabet, and for centuries that was considered secure. The simulation's built-in frequency-analysis attack shows exactly why it isn't — every language has a characteristic letter frequency distribution, and matching a ciphertext's frequencies against English's own reveals the key in seconds. That vulnerability motivated the search for ciphers whose security doesn't depend on keeping the *method* secret, only the *key* — a principle known as Kerckhoffs's principle that underlies every modern algorithm on this page.

The next leap is public-key cryptography, which solves a problem substitution ciphers can't: how do two people who have never met agree on a secret key over a channel an eavesdropper is actively watching? Diffie-Hellman key exchange answers this using the discrete logarithm problem — it's easy to raise a number to a power modulo a prime, but hard to reverse the operation and recover the exponent. RSA takes a related but distinct hard problem, factoring the product of two large primes, and uses it to build a full public/private keypair: anyone can encrypt with the public key, but only the holder of the private key (derived from the original primes) can decrypt. Elliptic curve cryptography achieves the same goal with a different hard problem — the elliptic curve discrete logarithm — that offers equivalent security with dramatically smaller keys, which is why it now secures most HTTPS connections and virtually all cryptocurrency wallets.

The second half of the hub moves from keeping secrets to keeping records honest. A cryptographic hash function like the one in the hash functions simulation takes any input and produces a fixed-size fingerprint with two critical properties: flipping a single input bit changes roughly half the output bits (the avalanche effect), and finding two different inputs that hash to the same output should be computationally infeasible, even though the birthday paradox makes collisions likelier than raw intuition suggests. The Merkle tree simulation shows what you can build once hashing is cheap and reliable: hash data blocks pairwise up to a single root hash, and you can prove any one block is included in the set with only a handful of hashes, not the entire dataset — the structure behind every blockchain's efficiency.

Blockchain consensus ties keys and hashes together into a system that lets mutually distrusting parties agree on a shared history without a central authority. The blockchain consensus simulation shows Proof-of-Work mining in action — miners race to find a hash below a difficulty target, the longest valid chain wins when forks occur, and a simulated 51% attacker's odds of rewriting history are shown explicitly, illustrating exactly why that threshold matters. The distributed consensus, consistent hashing and Bloom filter simulations broaden the picture to distributed systems more generally: Raft and Byzantine fault tolerance solve the agreement problem even when some participants fail or lie, consistent hashing lets a distributed cache or database scale without reshuffling every key whenever a server joins or leaves, and a Bloom filter answers set-membership questions at scale with no false negatives and a tunable false-positive rate.

Together these ten simulations trace cryptography's full arc — from a 2,000-year-old substitution cipher that frequency analysis breaks in seconds, through the public-key mathematics that makes the modern internet possible, to the hashing and consensus mechanisms that let a blockchain function without a bank in the middle. Every protocol here runs step by step exactly as specified, so the keys, hashes and consensus outcomes you see are the actual outputs of the algorithms, not simplified stand-ins — useful whether you're studying for a security exam, building intuition before reading an RFC, or just curious how HTTPS actually keeps a secret.

Frequently Asked Questions

Common questions about cryptography and blockchain consensus

Why is RSA considered secure?
RSA's security relies on the fact that multiplying two large prime numbers is fast, but factoring their product back into the original primes is computationally infeasible with classical computers for sufficiently large keys (2048 bits or more in practice). There is no known efficient classical algorithm for factoring large numbers.
What is the difference between Diffie-Hellman and RSA?
Diffie-Hellman lets two parties derive a shared secret key over an insecure channel using the discrete logarithm problem; it doesn't encrypt messages by itself. RSA is a full public-key encryption and signature scheme based on the difficulty of factoring, so it can encrypt data directly or sign it, not just establish a shared key.
How does Proof-of-Work actually secure a blockchain?
Proof-of-Work requires miners to spend real computational effort finding a hash below a target threshold before their block is accepted. Because the longest valid chain wins in a fork, rewriting history requires re-mining every block after the point you want to change faster than the rest of the network combined — the basis of the 51% attack threshold.
What makes a hash function "cryptographic"?
A cryptographic hash function must be one-way (infeasible to recover the input from the output), collision-resistant (infeasible to find two inputs with the same output), and exhibit the avalanche effect, where a single-bit input change flips roughly half the output bits, so similar inputs never produce similar-looking hashes.

Other Topic Hubs

Every simulation in this hub runs entirely in your browser, with no installation required. Use each interactive model to experiment with ciphers, keys, hashes and consensus protocols, then learn cryptography online at your own pace by tweaking parameters and watching the mathematics play out.