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

PurposeReversible?Example
EncodingChange the format so data travels safelyYes, by anyone. No secret.Base64 (aGVsbG8= is "hello"), URL encoding
EncryptionKeep data secretYes, but only with the keyAES, RSA, ChaCha20
HashingFingerprint data to check integrityNo (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?

PlainABCDEFGHIJKLMNOPQRSTUVWXYZ
CipherDEFGHIJKLMNOPQRSTUVWXYZABC

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.

Plaintext01010000 01000001 01011001
Key (repeated)01101100 01101100 01101100
XOR result00111100 00101101 00110101

XOR truth table

ABA XOR B
000
011
101
110

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.

4 steps
Press Play and the tutor will talk you through it while writing on the board. Pause any time to write on the board yourself.

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

Question 1

1.A config file stores a password as cGFzc3dvcmQxMjM=. How protected is it?

Question 2

2.Which is used to encrypt a whole laptop disk?

Question 3

3.To send Bob a secret, which key do you encrypt it with?

Question 4

4.What does forward secrecy protect against?

Question 5

5.Why is ECB mode a bad choice?

Quiz score: 0 of 5

Tip: answer every quiz question correctly first.

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.