A hands-on field guide to how secrets are kept: from a Roman general's alphabet trick to the mathematics protecting your bank login. Every exhibit below runs live in your browser. Nothing leaves this page.
Julius Caesar protected military orders by replacing each letter with the letter a fixed number of positions further along the alphabet. A shift of 3 turns A into D, B into E, and so on. To read the message, the recipient simply shifts back.
The "key" here is just the shift amount: a single number between 1 and 25. Keep that in mind, because it is exactly what breaks this cipher.
An obvious upgrade: instead of shifting the alphabet, scramble it completely. Map each letter to any other letter. Now there are about 403,000,000,000,000,000,000,000,000 possible keys (26 factorial). Surely unbreakable?
The Arab scholar Al-Kindi showed otherwise. Languages have fingerprints: in English, E appears far more often than any other letter, followed by T, A, O. Count the letters in the ciphertext, and the disguise slips. This is frequency analysis, and it is why a huge keyspace alone is not enough.
Notice the tallest red bar. Whatever letter it is, it is almost certainly playing the role of E. Pull that thread and the whole cipher unravels, one letter at a time.
Modern symmetric ciphers like AES are the industrial descendants of everything above. Same core idea: one secret key both locks and unlocks the message. The difference is that AES operates on bits rather than letters, mixes them through many rounds, and its output is statistically indistinguishable from random noise. No frequency fingerprint survives.
Symmetric encryption is fast, which is why it protects data at rest (full-disk encryption, encrypted databases) and data in bulk. Its weakness is not the math. It is logistics: both parties must already share the key. How do you deliver a secret key over an insecure channel? Hold that thought for Exhibit 04.
The breakthrough of the 1970s: use two mathematically linked keys instead of one. The public key can be shouted from the rooftops; anyone can use it to encrypt a message to you. Only the matching private key, which never leaves your possession, can decrypt it. Flip the direction and you get digital signatures: sign with your private key, and anyone can verify with your public one.
One shared key locks and unlocks. Fast. Great for bulk data. Problem: securely sharing the key in the first place.
Public key encrypts, private key decrypts. Slow, but nothing secret ever needs to travel. Great for key exchange and signatures.
In the real world the two are combined: your browser uses asymmetric cryptography for a few milliseconds to agree on a fresh symmetric key, then AES does the heavy lifting for the rest of the session. That handshake is the "S" in HTTPS.
Real RSA uses primes hundreds of digits long. This toy version uses tiny ones so you can watch the machinery. It encrypts each character separately, which real RSA never does, but the math is genuine.
Here is the most common confusion in the field, so read this twice: hashing is not encryption. Encryption is reversible by design; whoever holds the key gets the message back. A hash function is a one-way meat grinder. It takes input of any size and produces a fixed-length fingerprint, and there is no key and no way back.
That one-way property is exactly what you want for storing passwords (the site checks your fingerprint without ever storing the password itself), verifying downloads have not been tampered with, and detecting whether any file has changed.
The question is never "which is strongest?" but "what property do I need?" Do you need the data back later? Then you need encryption, and a key. Do you only need to verify or compare? Then you need a hash, and storing a key would be a liability.
| Situation | Tool | Why |
|---|---|---|
| Storing user passwords | Hash (salted, slow: Argon2/bcrypt) | You never need the password back, only to check a match. If breached, no key exists to leak. |
| Encrypting a laptop drive | Symmetric (AES) | Bulk data, one owner, speed matters. The key stays with the owner. |
| Sending your credit card to a website | Asymmetric handshake, then symmetric session | No pre-shared key exists between you and the site. TLS uses public-key crypto to agree on an AES key, then AES takes over. |
| Verifying a downloaded file is intact | Hash (SHA-256) | Compare fingerprints. Any tampering changes the hash completely. |
| Proving an email really came from you | Digital signature (asymmetric) | Sign with your private key; anyone verifies with your public key. Confidentiality is not the goal, authenticity is. |
| Encrypting a database of customer records | Symmetric (AES), keys in a key management system | Large volumes, frequent access: symmetric speed, with careful key handling. |