Study Guide
Encryption
Why data sent across a network is scrambled so that anyone who intercepts it cannot read it, how a key turns plaintext into ciphertext and back, and the difference between symmetric encryption (one shared key) and asymmetric encryption (a public key and a private key).
Lesson 4.4 Networks, the Internet and Security
For: Cambridge IGCSE Computer Science learners, or anyone who has seen a padlock in a web address and wondered what it means
Stage: Think
Paying over a café’s Wi-Fi
Aisha is buying a concert ticket on her phone while she sits in a fictional café. The phone uses the café’s Wi-Fi, which every customer shares. The packets that carry her card number travel through the air, and someone else at a nearby table, with the right software, could capture them as they pass.
Think it through
Can the café stop other customers from capturing the packets? If it cannot, what could Aisha’s phone do to the card number before sending it, so that a captured packet is of no use to the person who captured it?
- Hint 1: Think about the radio signal: can you stop a signal that is sent through the air from reaching someone who is near?
- Hint 2: What if the packet held something that looked like nonsense?
Show a model answer
The café probably cannot stop the capture: a signal sent through the air reaches everyone in range. But the phone can scramble the card number in a way that only the ticket website can undo, so that a captured packet looks like nonsense to anyone else.
Stage: Discover
Scrambling with a secret number
One of the oldest ways to scramble a message is a shift: replace every letter with the letter a fixed number of places along the alphabet. Here the number is 3, so A becomes D, B becomes E, and so on, going back to the start after Z:
Plain: ABCDEFGHIJKLMNOPQRSTUVWXYZ
Shifted: DEFGHIJKLMNOPQRSTUVWXYZABCThink it through
Using this shift of 3, scramble the word GATE. What does it become?
- Hint 1: Find each letter in the top row, then read the letter below it.
Show what happens
G becomes J, A becomes D, T becomes W and E becomes H, so GATE becomes JDWH.
Scrambling data so that it cannot be understood by anyone who does not know how to unscramble it is called encryption. Three terms describe the parts of the process:
- plaintext: the data before it is encrypted (here, GATE). It is called plaintext even if it is a photo or a card number, not text;
- ciphertext: the data after it has been encrypted (here, JDWH);
- key: the secret value that the process needs in order to scramble the data and unscramble it (here, the number 3).
Turning ciphertext back into plaintext is decryption. In a real system, the rule that scrambles the data is public and is built into software; the secret is the key.
| Plaintext letter | Ciphertext letter |
|---|---|
| B | E |
| O | |
| O | |
| K |
- Look the letter up in the alphabet rows above.
- Count three letters along; after Z, go back to A.
Show the completed table
| Plaintext letter | Ciphertext letter |
|---|---|
| B | E |
| O | R |
| O | R |
| K | N |
Stage: Explain
Undoing it with the key
Think it through
Someone who knows that the key is 3 receives PHHW. How should they unscramble it? And what could someone who does not know the key try, if they have captured PHHW?
- Hint 1: The key moved every letter forward. What undoes a move forward?
- Hint 2: How many different shifts are there to try?
Show what happens
Whoever knows the key moves every letter back 3 places: P becomes M, H becomes E, H becomes E and W becomes T, so the message is MEET. Someone without the key could try shifts 1, 2, 3 and so on until the result reads as words. There are only 25 shifts that change anything, so they will find the right one quickly.
- Write down what you know. The ciphertext is PHHW DW QRRQ, and the key is 3: each letter was moved 3 places along, so it must be moved 3 places back.
- Move each letter back three places, and leave the spaces. P, O, N, M: P becomes M. H becomes E. H becomes E. W becomes T. The first word is MEET.
- Do the next words in the same way. D becomes A and W becomes T, giving AT. Q becomes N, R becomes O, R becomes O and Q becomes N, giving NOON.
- Check by encrypting again. Moving MEET AT NOON forward by 3 gives PHHW DW QRRQ again, so the working is right.
The plaintext is MEET AT NOON.
| Ciphertext letter | Plaintext letter |
|---|---|
| P | L |
| M | |
| F | |
| V | |
| E | |
| V | |
| C |
- The key is 4, so move each letter four places back.
- If you go back past A, start again at Z.
Show the completed table
| Ciphertext letter | Plaintext letter |
|---|---|
| P | L |
| M | I |
| F | B |
| V | R |
| E | A |
| V | R |
| C | Y |
A shift like this is not safe: with only 25 possible keys, anyone can try them all. Real encryption keys are much, much longer, so there are far too many keys to try. A key of 128 bits, which is common, can have any of about 3.4 × 10 to the power 38 values. The shift cipher is only a way of seeing the ideas of plaintext, ciphertext and key.
Stage: Predict
What encryption does, and does not do
Back at the café, Aisha’s phone now encrypts her card number before it sends it.
Think it through
With the card number encrypted, can the person at the next table still capture the packets? What can and can’t they do with what they capture?
- Hint 1: Does encrypting a packet make it invisible, or does it make it unreadable?
Show what happens
They can still capture the packets: encryption does not hide them or stop them being copied. But what they captured is ciphertext, which means nothing without the key. Encryption does not prevent interception; it makes an intercepted message useless.
That is the purpose of encryption when data is sent across a network: to keep it private when it can be intercepted. It is needed wherever data crosses a network that others might be able to listen to: card numbers, passwords, private messages and school records.
Check your understanding
Show the answer
Answer: A. Not quite: the packets can still be captured, but the data is unreadable without the key.
Encryption protects the meaning of the data, not the packets.
Stage: Discover
One key for both people: symmetric encryption
The shift cipher uses the same key, 3, to encrypt and to decrypt. Ticket website and phone must both know it.
- Hint 1: Who can see everything sent across the café’s Wi-Fi?
- Hint 2: What would a person who captured the key be able to do with the encrypted messages?
Show what happens
If the key is sent across the Wi-Fi, the person at the next table can capture it, together with the encrypted messages, and decrypt everything. The key needs to be passed on by a way that nobody else can see, but that is the same problem again.
When one key is used to encrypt and to decrypt, the method is symmetric encryption. Both sides need a copy of the same key, which is called a shared secret key.
- Advantage: it is fast and uses little computing power, so it suits large amounts of data.
- Disadvantage: the key has to be shared between the two sides first, and it cannot be sent safely along the same network. If someone intercepts the key, they can read everything. A person who talks to many people also needs a different key for each.
Stage: Explain
Two keys: a padlock anyone can close
The secretary of a fictional school, Mira, wants parents to send private forms. She does not want to meet every parent to hand over a secret key.
Think it through
Mira puts a box in the school reception. How could she let any parent lock a form in the box, so that nobody except her can open it? Think of padlocks and keys.
- Hint 1: What if the padlock could be closed without a key?
- Hint 2: Who needs the key, and who does not?
Show what happens
Mira leaves a stack of open padlocks next to the box. Any parent can take one, put the form in the box and snap the padlock shut. The padlocks are the same for everybody, and anyone may have one, but Mira keeps the only key that opens them. Nobody else, including the parent who locked the box, can open it again.
Asymmetric encryption works in the same way, but with two keys that are different and linked as a pair:
- the public key, which is not secret: it is given to anyone, as Mira’s open padlocks are. It is used to encrypt;
- the private key, which is kept secret by its owner, like Mira’s key. It is used to decrypt.
Data encrypted with a public key can only be decrypted with the matching private key. Even the public key cannot undo what it did, as the padlock cannot be reopened without the key.
Each step names the device that acts. Watch which key is used to encrypt, and which to decrypt.
The ticket website
Step 1 of 5: It makes a pair of keys
The website makes a public key and a matching private key. It keeps the private key secret.
The ticket website
Step 2 of 5: It sends the public key to the phone
The public key can be sent in the open: it is safe if the person at the next table sees it.
Aisha’s phone
Step 3 of 5: The phone encrypts the card number with the public key
The plaintext, the card number, becomes ciphertext.
The café’s Wi-Fi
Step 4 of 5: The ciphertext travels, and is captured
The person at the next table captures the packets. They have the ciphertext and the public key, but the public key cannot decrypt it.
The ticket website
Step 5 of 5: It decrypts the card number with the private key
Only the private key matches the public key that was used. The website now has the plaintext card number.
Check your understanding
Show the answer
Answer: C. Mira’s private key, the other key in the same pair.
The private key, which only Mira has, is the only key that decrypts it.
Apply it
Show the answer
Answer: D. The public key can only encrypt, so it cannot read forms; only the private key can.
Everyone has the public key, so it must not be able to decrypt anything. Only the private key decrypts.
Do not confuse: One key or two
- One keySymmetric encryption
- The same secret key encrypts and decrypts. Fast, but the key has to be shared safely first.A shift cipher with the key 3.
- Two keysAsymmetric encryption
- A public key encrypts and the matching private key decrypts. No secret key has to be sent, but it is slower.Mira’s padlocks and her key.
The public key is shared with everyone. The private key is never shared.
| Statement | Symmetric or asymmetric? |
|---|---|
| One key is used to encrypt and decrypt | |
| A public key encrypts, and only the private key decrypts | |
| The key has to be shared secretly before the first message | |
| The key used to encrypt can safely be given to anyone | |
| Faster, so better for large amounts of data |
- How many keys does the statement involve?
- Which of the two methods has a secret that has to be shared?
Show the completed table
| Statement | Symmetric or asymmetric? |
|---|---|
| One key is used to encrypt and decrypt | symmetric |
| A public key encrypts, and only the private key decrypts | asymmetric |
| The key has to be shared secretly before the first message | symmetric |
| The key used to encrypt can safely be given to anyone | asymmetric |
| Faster, so better for large amounts of data | symmetric |
Go deeper Using both together
Asymmetric encryption is slower, so websites usually use it only at the start of a visit, to agree a shared secret key safely. They then use that key for symmetric encryption of the pages and forms, which is much faster. This is roughly what happens when a web address starts with https and your browser shows a padlock.
Stage: Consolidate
Show what you know
Apply it
Show the answer
Answer: B. Symmetric: the key is already shared safely, and it is fast for large amounts of data.
Symmetric: one shared key, already passed on safely, and a method that is fast on large data.
Think it through
Explain to a friend how Aisha’s phone sends her card number to the ticket website in a way that the person at the next table cannot read. Use the words plaintext, ciphertext, public key and private key.
- Hint 1: Start with who has which key.
- Hint 2: End with what the person at the next table is left with.
Show a model answer
A good answer: “The website keeps a private key and sends the phone its public key. The phone uses the public key to turn the plaintext, the card number, into ciphertext. The ciphertext travels over the Wi-Fi. The person at the next table can capture it, but only the website’s private key decrypts it, so what they captured is useless.”
- Encryption scrambles plaintext into ciphertext using a key. It does not stop data being intercepted; it makes the intercepted data unreadable.
- Symmetric encryption uses one shared secret key to encrypt and decrypt. It is fast, but the key must be shared safely first.
- Asymmetric encryption uses a pair of keys: the public key (shared with everyone) encrypts, and only the matching private key (kept secret) decrypts. No secret has to be sent, but it is slower.
- A simple shift has only 25 keys, so anyone can try them all. Real keys have far too many values to try.
Sources and scope
- What this lesson is. The fourth lesson of the Networks, the Internet and Security module, written for this site. Its curriculum links are provisional: the wording of each linked specification point has been checked against the published specification, but no link has been verified by the site owner, and the links imply no endorsement by any examination board.
- Original material. Aisha and the café, the ticket website, Mira and the school reception box, Leo’s claim, the hospital backup and every message and ciphertext are fictional examples written for this lesson, and each shift was worked out twice.
- Simplified on purpose. The shift cipher is far weaker than real encryption and is used only to show the ideas. The lesson does not explain the mathematics of real symmetric and asymmetric methods, how keys are generated, digital signatures, digital certificates or how a browser checks that a website is the one it claims to be. Those belong to later study.
Encryption that uses a pair of keys: a public key to encrypt and the matching private key to decrypt.
A single binary digit: 0 or 1. The smallest unit of data a computer stores.
Data after it has been encrypted.
Turning ciphertext back into plaintext using the key.
Scrambling data with a key so that it cannot be understood by anyone who does not have the key to unscramble it.
The secret value needed to encrypt data and to decrypt it.
A small piece of data sent across a network, with a header, a payload and a trailer.
Data before it is encrypted; it need not be text.
The key of a pair that its owner keeps secret and uses to decrypt.
The key of a pair that is given to anyone and is used to encrypt.
Encryption in which the same secret key is used to encrypt and to decrypt.
Software that requests web pages, then renders their HTML and displays them to the user.
Your progress on this lesson
Saved in this browser only. It is not sent anywhere, does not follow you to another device, and is lost if you clear this site’s data.
This browser is not allowing the site to save progress, so it will be forgotten when you leave the page.