← Back to Portfolio
Cambridge A Level Computer Science
Topic 17 · Security · Lesson 3

Encryption: Keeping Data Secret

Every message you send online can be intercepted. This lesson is about how it stays unreadable regardless.

⏱ 45 min 9 key terms

By the end of this lesson, you should be able to assess the end-to-end security of a website login, from establishing a trusted connection to protecting the information sent over it.

If you're reading this over Wi-Fi you don't fully control, your device and this server are exchanging data across a network neither of you can fully see. Anyone positioned along that route could, in principle, capture every packet (message) that passes by.

Encryption is the layer that makes this irrelevant: even if the data is intercepted, it can't be read. The real question isn't whether your data can be seen in transit: it's what an attacker can actually do with it once they have it. That's what this lesson is about.

01 · Foundations

Plaintext, Ciphertext, and Keys

An encryption algorithm transforms readable plaintext into unreadable ciphertext, using a key, a piece of information that controls exactly how the transformation happens. Change the key, and the same plaintext produces completely different ciphertext.

Try it below with one of the oldest encryption methods on record: the Caesar cipher, which shifts every letter a fixed number of places through the alphabet. The amount that each letter shifts is the key.

Cipher Console

Use the slider to set a shift key and encipher the message below. Then, select the "Decipher" button to watch a computer try every possible key until it finds the one that deciphers the message.

That's the core weakness of any scheme with too small a key space: if there are few enough possible keys, brute force finds the right one. Modern algorithms don't fix this by hiding how they work (the method is usually public); they fix it by making the key space astronomically large.

02 · Two Strategies

Symmetric vs Asymmetric Encryption

Every practical encryption system has to solve two problems: how to scramble the message, and how the sender and receiver agree on a key without anyone else getting hold of it. Symmetric and asymmetric encryption differ mainly in how they solve that second problem.

Symmetric

One shared secret key both encrypts and decrypts. It's fast, but Alice and Bob both need the exact same key before they can talk securely, which means that key has to be delivered somehow. Whatever route it takes to reach Bob, that moment of delivery is a risk.

Asymmetric

Each person has a matched key pair: a public key, shared freely, and a private key, kept secret and never sent anywhere. Only the private key can decrypt what the public key encrypted.

Key Exchange Simulator

Alice and Bob need to share one secret key before they can talk. Press send to watch the exchange.

A Alice B Bob E Eve (eavesdropper)
  • No activity yet: press send to begin.

This is the reason HTTPS, secure messaging apps and online banking rely on asymmetric encryption to get started, even though it's slower than symmetric encryption. In practice, most systems use asymmetric encryption just long enough to safely agree on a temporary symmetric key, then switch to symmetric encryption for the rest of the conversation, because it's faster.

03 · A One-Way Street

Hashing Isn't Encryption

Encryption is designed to be reversed: with the right key, ciphertext transforms back into original plaintext. Hashing is designed to be a one-way street. A hash function takes input of any length, from a single letter to a multi-gigabyte file, and maps it to a fixed-length string of characters called a digest. It achieves this by scrambling the input's bits through multiple rounds of mathematical operations like shifting, combining, and mixing until the output bears zero resemblance to the original.

Unlike encryption, which relies on a key to reverse the process, hashing cannot be undone for two fundamental reasons. First, the mathematical operations used during mixing have no clean inverse to run backward. Second, squeezing arbitrary amounts of data into a fixed-size digest intentionally discards information. Because multiple different inputs could technically yield the identical digest (a collision), there is no unique original to recover. It is less like locking a document in a safe and more like blending fruit into a smoothie: no amount of skill can run the blender in reverse to get your whole apple back.

Hash Playground

Illustrative digest, not a real cryptographic hash algorithm.

Type anything below: one letter or a full paragraph. The digest never changes length.

That unpredictability, combined with the lack of any reverse key, means the only way to figure out what created a specific digest is to guess inputs, hash them, and compare results. This one-way design is precisely what makes hashing ideal for password security. A system verifies your login by hashing the password you type and comparing the result to the stored digest, allowing it to validate your identity without ever needing to store (or even know) your actual password.

04 · Trusting a Key

Digital Certificates

Asymmetric encryption solves key distribution, but it raises a new question: if Bob's public key just appears from somewhere, how does Alice know it's really his, and not an attacker's? A digital certificate answers that. It's Bob's public key, bundled with his identity, and digitally signed by a Certificate Authority, an organisation both Alice's browser and Bob already trust.

When Alice's browser connects, it checks that signature before trusting the key at all. That check, repeated automatically thousands of times a day, is what the small padlock next to a web address is actually reporting.

🔒https://www.onlinebanking.example
Certificate verified: this key really does belong to onlinebanking.example.
Page content loads only after this check passes.
Certificate Inspector

Real browsers let you inspect a certificate behind the padlock. Click each field below to see what it means and why it's checked.

The exact domain this certificate is issued for. Your browser checks that it matches the address bar precisely. Even a single extra letter, like onlinebankinng.example, would fail this check.

The Certificate Authority that verified this domain and signed the certificate. Browsers only trust a small, built-in list of these authorities. A certificate signed by anyone outside that list, including one that simply signs itself, gets flagged as untrusted.

Certificates expire on purpose. A shorter lifespan limits how long a compromised key could keep being trusted before anyone notices. An expired certificate is treated the same as an untrusted one.

The actual public key this certificate is vouching for. Once everything else checks out, this is the key your browser uses to encrypt data meant for this server, the same kind of public key from the asymmetric encryption earlier in this lesson.

A cryptographic signature over every other field on this certificate, produced with a private key. Change the domain or the public key by even one character, and the signature no longer matches, which is what makes tampering detectable. But anyone can produce a signature, including the certificate itself. What actually makes it trustworthy is whether that signature came from a recognised Certificate Authority rather than from the certificate signing itself.

Every one of those fields exists to answer the same question: does this public key really belong to who it claims to? Get that answer wrong, and it doesn't matter how strong the encryption is afterward: you'd just be encrypting very securely to the wrong person.

Task

Implement the Secure Handshake

You've been asked to build the login flow for a banking site. There are four decisions needed to secure the connection, all while someone else is watching the transaction:

  1. Verify who you're talking to.
  2. Agree on a key without leaking it.
  3. Move the data efficiently.
  4. Decide how to protect the password sent at login.

Make all four decisions then conduct a security review of your implementation.

Task Console
Your setup
Cert-
Key-
Transfer-
Password-
Step 1: Verify Server Identity
Digital Certificates & Certificate Authorities

Your login flow is connecting to https://secure-bank.com. Two certificates come back, both claiming to belong to that domain. Which one should you trust?

Certificate A

Domain: secure-bank.com

Public key: 0x9F4A...82B

Signed by: Self-signed

Certificate B

Domain: secure-bank.com

Public key: 0x3C81...19F

Signed by: DigiCert Global Root CA

Step 2: Establish a Session Key
Asymmetric Encryption

With the certificate check handled, your login flow needs to send a new session key to the server so both sides can switch to something faster. Someone else is watching the transaction the whole time.

[ Client ] ——— ( Eve Watching ) ———› [ Server ]

Option A: Send the session key in plaintext

Transmit it directly, unencrypted, so the server can read it immediately.

Option B: Encrypt the session key with the server's public key

Scramble it using the public key you were given before sending it to the server.

Step 3: Bulk Data Transmission
Symmetric vs Asymmetric Performance

A session key has been sent. Now you need to stream a 500 MB account archive between client and server. Which approach fits?

Asymmetric encryption

Encrypt every packet using the public/private key pair.

Symmetric encryption

Encrypt every packet using the session key exchanged in Step 2.

Step 4: Login Verification
One-Way Hashing

Last step: authenticate with your account password, SuperSecret123. How should it be handled?

Option A: Encrypt it and store the encrypted password

Send it encrypted so the server can decrypt and store it for later comparison.

Option B: Hash it and compare digests

Compute the password's digest and check it against the digest already stored on the server.

Security Audit
How your setup actually held up