Module 6 · Cryptography and PKI · Lesson 16 of 75
Encryption: symmetric, asymmetric and key exchange
Encoding versus encryption versus hashing, classic ciphers you can play with, AES, RSA and elliptic curves, and how two strangers agree on a secret key.
In this lesson · about 40 minutes
- Tell encoding, encryption and hashing apart
- Explain symmetric and asymmetric encryption and when each is used
- Describe how Diffie-Hellman key exchange creates a shared secret
Encoding, encryption, hashing
| Purpose | Reversible? | Example | |
|---|---|---|---|
| Encoding | Change the format so data travels safely | Yes, by anyone. No secret. | Base64 (aGVsbG8= is "hello"), URL encoding |
| Encryption | Keep data secret | Yes, but only with the key | AES, RSA, ChaCha20 |
| Hashing | Fingerprint data to check integrity | No (one-way) | SHA-256, bcrypt |
A common beginner mistake, and a common finding in real tests: "the password is encrypted" when it is only Base64-encoded.
Classical ciphers
The Caesar cipher shifts every letter by a fixed amount; the Vigenère cipher uses a keyword to vary the shift. Both are easily broken today, but they teach the vocabulary: plaintext, ciphertext, key, algorithm, and why a small key space (only 25 Caesar shifts) is fatal.
Try it: interactive cipher
Try a Caesar cipher
Type a message and change the shift. Then ask yourself: how long would it take to try all 25 shifts?
Ciphertext
PHHWDWWKHQRUWKJDWH
Try it: interactive cipher
XOR: the building block of modern ciphers
Your text is turned into bits and XORed with the key stream (the key repeats). Modern stream ciphers work the same way with a long, random key stream. XOR the result again with the same key and you get the original back. That is also why reusing a key stream is a disaster.
XOR truth table
| A | B | A XOR B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
Same bits give 0; different bits give 1.
Decrypt: XOR the result with the same key
01010000 01000001 01011001
Back to text: PAY
Symmetric encryption
- One shared key encrypts and decrypts. Fast, so it is used for bulk data: disks, files, the body of every HTTPS connection.
- AES (128- or 256-bit keys) is the standard; ChaCha20 is common on phones. DES and 3DES, RC4 are obsolete.
- Modes matter: ECB encrypts identical blocks to identical output and leaks patterns (never use it). GCM encrypts and detects tampering ("authenticated encryption") and is the usual choice.
- The hard part is key distribution: how do you give the key to the other side without someone copying it?
Asymmetric encryption
- A mathematically linked key pair. What the public key encrypts, only the private key decrypts. What the private key signs, anyone with the public key can verify.
- RSA (2048 bits or more) and elliptic-curve cryptography (ECC, such as P-256 and Curve25519, which gives the same strength with much shorter keys).
- Slow, so it is used for small things: exchanging keys, signatures, certificates.
Key exchange: Diffie-Hellman
Two parties each pick a private number, exchange public values derived from them, and each combines the other's public value with their own private number. Both arrive at the same secret, while an eavesdropper who saw only the public values cannot. Modern TLS uses ephemeral elliptic-curve Diffie-Hellman (ECDHE), with new keys for every session. That gives forward secrecy: stealing the server's private key later does not unlock old recorded traffic.
Quantum computing
A large quantum computer could break RSA and ECC. Standards bodies have published post-quantum algorithms (such as ML-KEM for key exchange), and browsers already combine them with classical key exchange. AES-256 and SHA-256 are considered safe.
Whiteboard · watch and try
Hybrid encryption: how HTTPS uses both
Press Play.
Tip: press Pause, then use the pen to work along on the board. Space plays and pauses; Ctrl+Z undoes your last mark.
Check your understanding0 of 5 correct
Quiz score: 0 of 5
Written by Noviq Academy in its own words. All labs are simulations: no real systems are touched, and every name, address, password and hash is made up. The offensive techniques taught here are for defending systems and for authorised testing only; never scan, access or test a system without the owner's written permission. Tool and product names belong to their owners, and command output may differ slightly from yours. Read-aloud uses your device's built-in voices.