Not sure which lesson to do first? Find your level and get a plan →

CS Thinking · Systems, Networks & Impact · Grade 6-8

Encryption

Encryption transforms readable data (plaintext) into an unreadable form (ciphertext) so that only someone with the correct key can recover the original.

ciphertext=Ek(plaintext)

Quick Answer

Encryption transforms readable data (plaintext) into an unreadable form (ciphertext) so that only someone with the correct key can recover the original. It protects data that other people might see: messages crossing Wi-Fi, a website login (the padlock and https in the address bar), the files on a lost laptop, chats that are end-to-end encrypted. Anyone can grab the ciphertext, but without the key it is useless. Encryption keeps data secret; it does not stop someone tricking you into handing over your password.

Why This Matters

When you log in over café Wi-Fi, anyone nearby could capture the data passing through the air; encryption makes that capture worthless. It is also why a stolen phone with encryption switched on does not give up its photos, and why a secure messaging company cannot read your chats. Knowing what encryption does, and what it cannot do, stops you trusting it for jobs it was never meant for.

Intuitive Explanation

Start with a simple cipher. Shift every letter 3 places along the alphabet: A becomes D, B becomes E, and X, Y, Z wrap round to A, B, C. 'MEET AT NOON' becomes 'PHHW DW QRRQ'. The rule, shift the letters, is the method; the number 3 is the key. Anyone who sees 'PHHW DW QRRQ' sees nonsense, but your friend, who knows the key, shifts each letter back 3 and reads the message.

A shift cipher is easy to break, because there are only 25 useful keys to try. Real encryption, like the AES method built into phones and laptops, follows the same idea of a method plus a secret key, but its keys are 128 bits or longer. That gives so many possible keys that trying them all would take billions of years even with the fastest computers. This is why encrypted data counts as unreadable without the key, not merely hard to read.

Encryption is not the same as hiding or locking. A password on a shared folder stops people opening it through the normal app, but the files underneath may still be readable to anyone who copies the disk; encrypted files are scrambled, so a copy is useless without the key. Encryption is also not all of security: if a fake email tricks you into typing your password, the attacker logs in as you, and the app decrypts everything for them.

Think of it like this. Encryption is like sending a message in a locked box that anyone can carry but only the key holder can open: the postman, a thief or a nosy neighbour can hold the box and learn nothing. The comparison fails in one useful way: a real box can be smashed open, while strong encryption cannot be forced in any practical amount of time.

Core idea. Encryption protects confidentiality by making data unreadable without the correct key.


When to Use

Use encryption when data must stay secret even though other people can see it or intercept it: messages over Wi-Fi, logins, files on a device that could be lost, end-to-end chats. Signals: plaintext, ciphertext, key, HTTPS, the padlock icon. If the question is about stopping attackers getting in or tricking users, use the wider idea, Cybersecurity; if it is about who is allowed to collect your data, use Privacy.

Tip. Ask: Is data being scrambled so that only someone holding the right key can turn it back into readable form?

How to Recognize It

Before you choose encryption, check whether the data needs hiding from people who can get hold of it but should not read it.

  1. Could someone other than the intended reader get the data, such as on public Wi-Fi or from a lost phone?

    Yes is where encryption helps. If the danger is someone tricking you into handing over a password, the defense is wider Cybersecurity, not encryption.

  2. Can the right person turn the scrambled version back into the original?

    Yes means encryption, which works both ways with a key. If no one can ever reverse it, as with stored passwords, it is Hashing.

  3. Is the data being made smaller rather than secret?

    Yes points to Data Compression. A zipped file can look scrambled, but anyone can unzip it without a key.

  4. Is the question about whether the data should be collected at all?

    Yes points to Privacy. Encryption protects data once someone has it; it does not decide who should have it.

Encryption vs Hashing vs Data Compression vs Cybersecurity

Encrypted, hashed and compressed data can all look like gibberish on screen. Ask whether a key brings it back, nothing brings it back, or anyone can bring it back.

Encryption

Meaning
Encryption turns readable plaintext into ciphertext that can be turned back only with the matching key.
Key test
It can be reversed, but only with the key.
Formula
Dk(Ek(plaintext))=plaintext
Example
A laptop's disk encryption keeps files unreadable to a thief who takes out the drive.

Hashing

Meaning
Hashing turns data into a fixed-length code that cannot be turned back into the original.
Key test
One-way: nothing reverses it, but the same input always gives the same code.
Formula
h=H(password)
Example
A website stores your password's hash and checks a login by hashing what you type and comparing.

Data Compression

Meaning
Data compression rewrites a file in fewer bits so it is smaller, without hiding anything.
Key test
Anyone can undo it; no key is needed.
Example
A plain ZIP file of homework opens on any computer with no password.

Cybersecurity

Meaning
Cybersecurity is the whole job of protecting systems and data, and encryption is only one of its tools.
Key test
It includes passwords, updates, backups and people, not only scrambling.
Example
A company that encrypts its data but never updates its servers is still exposed.

Formula & Notation

ciphertext=Ek(plaintext)
Encryption applies an algorithm E and a key k to plaintext to produce ciphertext. Decryption uses a corresponding key to recover the original plaintext.

Worked Examples

Example 1 — Encrypt and decrypt with a shift cipher

Easy

Use a shift cipher with key 4 (A → E, B → F, and so on, with W → A, X → B, Y → C, Z → D). Encrypt the word CODE. Then decrypt LIPPS, which was made with the same key.
Show the steps and the answer
  1. Encrypt by moving each letter 4 forward: C → G, O → S, D → H, E → I.

    The key, 4, sets how far to shift, and every letter uses the same shift.

  2. Write the ciphertext: GSHI.

    Someone who intercepts GSHI sees no real word unless they know the key.

  3. Decrypt LIPPS by moving each letter 4 back: L → H, I → E, P → L, P → L, S → O.

    Decryption uses the same key in reverse.

Answer: CODE encrypts to GSHI; LIPPS decrypts to HELLO.

Takeaway: The same method and key, run forward, encrypt; run backward, they decrypt. Without the key, the ciphertext means nothing.

Example 2 — Why a shift cipher is not real security

Standard

An attacker intercepts the shift-cipher message KHOOR but does not know the key. (a) How many keys must she try at most, and can she read the message? (b) A modern 128-bit key has 2128, about 3.4×1038, possible keys. At a trillion (1012) guesses per second, roughly how many years would trying them all take?
Show the steps and the answer
  1. (a) Count the keys: shifts of 1 to 25, so at most 25 tries.

    A shift of 26 brings every letter back to itself, so only 25 shifts scramble anything.

  2. Try them: shifting back by 3 turns K → H, H → E, O → L, O → L, R → O, which gives HELLO.

    A real word appears within 25 tries, so the cipher falls in minutes, even by hand.

  3. (b) Divide: 3.4×1038÷1012=3.4×1026 seconds.

    The number of keys divided by keys tried per second gives the time in seconds.

  4. Convert to years: a year is about 3.2×107 s, so 3.4×1026÷(3.2×107)≈1.1×1019 years.

    The universe is about 1.4×1010 years old, so this is close to a billion times its age.

Answer: (a) At most 25 keys; a shift of 3 reveals HELLO, so she can read it. (b) About 1.1×1019 years, close to a billion times the age of the universe.

Takeaway: Encryption is only as strong as its number of possible keys: a shift cipher has 25, a modern 128-bit key has over 1038.

Example 3 — Find the mistake: 'my chats are encrypted, so I'm safe'

Application

Nia's messaging app is end-to-end encrypted. She gets a text: 'Your account will be deleted. Log in here to keep it', with a link to a page that looks exactly like the app's login. She types her password and the code from her phone. Then she thinks: 'My chats are encrypted, so nobody can read them anyway.' Find the mistake.
Show the steps and the answer
  1. List what the attacker now has: Nia's password and her one-time code.

    With both, the attacker can sign in to her account on their own device as if they were Nia.

  2. Ask what encryption protects: messages travelling between devices and stored on the company's servers.

    It stops outsiders reading intercepted data, but someone signed in with the right details is treated as the owner, so new messages to her account are decrypted for them.

  3. Fix it: change the password straight away in the real app, sign out all other devices, and never log in through a link in a message.

    The weak point was a person being tricked, and only careful habits and account checks protect against that.

Answer: Encryption does not stop phishing. Nia handed over her password and code, so an attacker can sign in as her and the app will decrypt her messages for them. She should change her password in the real app, sign out other devices, and ignore login links in messages.

Takeaway: Encryption protects data from people without the key; it cannot protect you from handing the key over yourself.

Where You'll See It

  • The padlock icon in your browser

    When you log into a bank or store website, HTTPS encrypts your password and card number as they travel, so anyone intercepting the data on the Wi-Fi sees scrambled ciphertext, not your real info.

  • WhatsApp or iMessage 'end-to-end encrypted' chats

    Your message is locked with a key only your friend's device has, so even the messaging company's servers carry an unreadable version — only the right key recovers the plaintext.

  • A diary with a real lock vs. a coded one

    Encryption is like writing your diary in a cipher only you can decode — even if someone steals the diary (the data), they can't read it without the key, unlike a lock that just hides a readable page.

Common Mistakes

  1. The slip: Encrypted data can still be read if you just look hard enough.

    Why it's tempting: On a screen the scrambled text still looks like 'data,' so it feels like the meaning is hidden in plain sight.

    Instead: Without the correct key, properly encrypted ciphertext is computationally unreadable — looking harder doesn't recover the message; only the key does.

  2. The slip: Encryption alone makes a system completely secure.

    Why it's tempting: Encryption feels like the strongest lock, so it seems to solve every threat.

    Instead: Encryption protects confidentiality of data, but you still need strong passwords, updates, and protection against phishing and weak key handling.

  3. The slip: Encryption only matters for banks, spies, and governments.

    Why it's tempting: Everyday messages feel too unimportant for anyone to bother decoding.

    Instead: Encryption protects everyday users' passwords, chats, photos, and browsing — it's built into the apps and sites you use daily.


Mini Practice

Try these on your own. Tap Reveal when you want to check.

  1. Encrypt the word CAT with a Caesar cipher that shifts each letter 3 places forward in the alphabet (A becomes D).

    Hint: Count three letters forward from each letter.

  2. The message KHOOR was encrypted by shifting each letter 3 places forward. What was the original word?

    Hint: Undo the shift by counting back instead of forward.

  3. A Caesar cipher has only 25 useful shifts. If a computer tries one shift every 0.001 seconds, how long does it take to try all of them? What does that tell you?

    Hint: Multiply the number of keys by the time for each try.

  4. A key that is 8 bits long has 28 possible values. How many is that? How many does a 9-bit key have, and what happens each time one bit is added?

    Hint: Each bit can be 0 or 1, so think about doubling.

  5. A school wants student data safe if a laptop is stolen. Plan A: scramble the files so they are unreadable without a key. Plan B: a full plan with passwords, updates, backups and staff training. Which is encryption, and which is cybersecurity?

    Hint: One plan is a single tool; the other is a whole set of defences.

  6. Dev says: "My messages are encrypted, but anyone who intercepts them can still read them if they look closely." What is wrong with this idea?

    Hint: What is needed to turn ciphertext back into plaintext?

Want the full set?

50 practice questions for this concept — free to try, every one with a complete worked solution showing the why, not just the answer.

Frequently Asked Questions

Can encryption be broken?

Old and weak methods can. The letter-shifting code Julius Caesar used has only 25 useful keys, so you can try them all by hand in minutes. Modern encryption such as AES uses keys of 128 bits or more, which gives about 3.4×10383.4 \times 10^{38} possible keys, far too many for all the computers on Earth to try. Attacks today usually go after weak passwords or tricked users instead.

If my chats are end-to-end encrypted, is everything about them private?

Not everything. The words, photos and voice notes are locked so only your device and your friend's can read them. But the service may still see who you messaged, when, and how often, which can reveal a lot. And once your friend's phone shows the message, they can screenshot or forward it. Encryption protects the message on its way, not what people do after reading it.

Why do governments and tech companies argue about encryption?

Strong encryption protects ordinary people's messages and bank details, but it also hides criminals' messages from police who have a warrant. Some governments want companies to build a special way in. Security experts warn that any secret way in could also be found and used by attackers, which would weaken protection for everyone. It is a real debate between two kinds of safety, with no easy answer.

How do my browser and a website agree on a key without anyone overhearing?

They use public-key methods. Each side shares a number openly while keeping a private number secret, and clever math lets both sides end up with the same secret key, even though an eavesdropper sees everything they send. The website also proves who it is with a certificate. Then both switch to faster ordinary encryption using that shared key, all before the padlock appears.

Learning Path

Encryption

You are here

You should know Cybersecurity (protecting systems from attackers) and Privacy (control over your personal data), because encryption is a main tool for both. It adds the idea of a key: data scrambled into ciphertext that only the key can turn back into plaintext. Next, Ethics of Computing takes up harder questions encryption raises, such as whether police should ever be able to read encrypted messages.

See Also