Chapter 01

Fundamentals

Before getting into ciphers and handshakes, it helps to know what cryptography is trying to achieve and the vocabulary everyone uses.

What is cryptography?

Cryptography comes from the Greek kryptós (hidden) and graphein (to write). It is the practice of protecting information so that only the intended people can read it or trust it. Three related terms come up often:

The basic idea hasn't changed in 2,500 years. Readable plaintext goes through an algorithm that is controlled by a secret key, and comes out as unreadable ciphertext. Anyone with the right key can reverse the process. Anyone without it should learn nothing.

PlaintextHELLO
→
Encryptalgorithm + key
→
CiphertextKHOOR
→
Decryptalgorithm + key
→
PlaintextHELLO

What cryptography gives us

Security people often say "CIA": Confidentiality, Integrity and Availability. Cryptography covers the first two directly and adds two more of its own: authentication and non-repudiation. It does very little for availability.

GoalQuestion it answersTypical tool
ConfidentialityCan anyone else read this?Encryption (AES, ChaCha20)
IntegrityHas this been changed?Hashes, MACs (SHA-256, HMAC)
AuthenticationWho am I talking to? Did this come from them?MACs, digital signatures, certificates
Non-repudiationCan the sender deny sending it?Digital signatures (only the private-key holder could have signed it)
Encryption alone doesn't give integrity An attacker can flip bits in ciphertext even when they can't read it, and with some ciphers the change passes straight through to the plaintext. WEP fell to exactly this kind of attack (see Chapter 07). Modern systems use authenticated encryption, which checks integrity and confidentiality together.

Kerckhoffs's principle

In 1883 Auguste Kerckhoffs set out a rule that still shapes all serious cryptography:

A cryptosystem should stay secure even if everything about it, except the key, is public.Claude Shannon later put it as "the enemy knows the system".

So the algorithm is public and only the key is secret. That's why AES, RSA and TLS are published standards that anyone can study and attack. An algorithm that has survived decades of public cryptanalysis earns far more trust than a secret one. Keeping the design secret, known as security through obscurity, tends to fall apart as soon as someone reverse-engineers the product. The MIFARE Classic transport cards and the GSM A5/1 cipher are well-known examples.

A practical consequence is never roll your own crypto. Use well-reviewed libraries and standard protocols.

The three families

🔑 Symmetric

One shared secret key is used to encrypt and decrypt. It's fast and suited to bulk data. The hard part is getting the key to the other person safely.


Examples: AES, ChaCha20, (3)DES

🔑🔑 Asymmetric (public-key)

Each person has a key pair: a public key that can be shared with anyone and a private key they keep. It solves key distribution and enables signatures, but it's slow.


Examples: RSA, Diffie-Hellman, ECC, ML-KEM

#️⃣ Hashing

A one-way function that turns any input into a fixed-size fingerprint. There's no key and no way back to the input. It's used for integrity and password storage.


Examples: SHA-256, SHA-3, (MD5, SHA-1, both broken)

Real systems use all three together. This is called a hybrid cryptosystem. Asymmetric crypto agrees or exchanges a symmetric key, symmetric crypto encrypts the actual data, and hashes or MACs protect integrity. Every TLS connection, and so every HTTPS web page, works this way.

For n people who all want to talk privately, symmetric crypto needs n(n−1)/2 keys. With 1,000 users that's 499,500 keys. Asymmetric crypto needs just 2n (2,000). This is a popular exam question.

Encoding vs encryption vs hashing

People often confuse these three. Type something below and click Run a few times to see how each one behaves.

Same input, three treatments
Click Run more than once and watch which outputs change.

Encoding (Base64): no key, anyone can reverse it

Encryption (AES-256-GCM, fresh random key and IV each time)

Reversible only with the key:

Hashing (SHA-256): same input always gives the same output, and it can't be reversed

PurposeKey?Reversible?
EncodingFormat data for transport (email, URLs)NoYes, by anyone
EncryptionConfidentialityYesYes, with the key
HashingIntegrity, fingerprints, password storageNo (a MAC adds one)No

How attackers approach crypto

Cryptanalysts group attacks by what the attacker has to work with:

Data has three statesCrypto protects data in transit (TLS, WPA3, VPNs) and at rest (BitLocker, FileVault, database encryption). Protecting data in use, while it's being processed in memory, is harder. Confidential computing and homomorphic encryption are new approaches to it.

Knowledge check