Pearson Edexcel International GCSE Computer Science (4CP0) · 3.3–3.4 Data storage, compression and encryption
Mini-Lesson
Data storage, compression and encryption
2 missions. Guess, learn, then check. Your place is saved.
Mission 1How can a file shrink but still open exactly as before?
Mission 2Caesar hid his letters in a shifted alphabet. Could you crack it?
The specification points and sources are listed under the lesson: see Sources.
Mission 1
How can a file shrink but still open exactly as before?
Make a guess: How can a file shrink but still open exactly as before?
Data representation · compression
Why compress?
Compression makes a file smaller, so it uses fewer bits.
Smaller files need less storage space.
They take less time to send or download and use less bandwidth.
Common cases: streaming video and music, web pages, email attachments, photos on a phone.
Data representation · compression
Squeezing out repetition
Data often repeats: a row of 6 white pixels, then 3 black, then 4 white.
Instead of storing all 13 pixels, store each run as a count and a value: 6 W, 3 B, 4 W.
The original can be rebuilt exactly, bit for bit. Compression that loses nothing is lossless.
The more repetition there is, the more the file shrinks.
Quick check
?Two images are the same size. One is a logo with large areas of flat colour. The other is TV static, where neighbouring pixels are random colours. Which shrinks more using repetition, and why?
Data representation · compression
Run length encoding
Run length encoding (RLE) replaces each run of repeated data with a pair: how many times it repeats, then the value.
RLE is lossless. With little repetition it can make the data bigger, as every single value gains a count.
Your answer
?Encode this row of a 1-bit image using RLE pairs (count, then value): 1111000000001100
Data representation · compression
Lossy and lossless
Lossy compression permanently removes data, usually detail people are unlikely to notice.
JPEG (photos) and MP3 (music) are lossy.
Lossy: much smaller files, but lower quality and the original cannot be got back.
Lossless: the original is rebuilt exactly, but the file is not as small. Use it for text, program files and data.
Quick check
?Which file must be compressed using lossless compression?
Mission check
?How can a file shrink but still open exactly as before?
Data usually contains repetition. Lossless compression stores repeated patterns more efficiently, for example as a count and a value, so the file uses fewer bits and the original can be rebuilt exactly.
Mission 2
Caesar hid his letters in a shifted alphabet. Could you crack it?
Make a guess: Caesar hid his letters in a shifted alphabet. Could you crack it?
Data · encryption ciphers
The Caesar cipher
Encryption keeps data secret: intercepted data can't be read without the key.
An encryption algorithm turns plaintext into ciphertext.
Caesar cipher: shift every letter the same number of places, wrapping from Z to A. The shift is the key. Shift 3: A→D, B→E, X→A.
Only 25 shifts are useful, so an attacker can try them all: a brute-force attack.
Your answer
?Encrypt ZEBRA with a Caesar cipher, shift 3.
Data · encryption ciphers
The Vigenère cipher
The Vigenère cipher uses a keyword instead of one shift.
Write the keyword repeatedly under the plaintext. Each key letter gives that letter's shift: A = 0, B = 1 … Z = 25.
Example: ATTACK with keyword LEMON gives LXFOPV.
The same plaintext letter can become different ciphertext letters, so it is much harder to crack than Caesar.
Your answer
?Encrypt HELLO with the Vigenère cipher, keyword KEY.
Data · encryption ciphers
The rail fence cipher
The rail fence cipher moves letters around instead of replacing them.
Write the plaintext in a zigzag down and up across a number of rows, the rails. The number of rails is the key.
Read each rail from left to right, top rail first, to get the ciphertext.
MEETATDAWN on 3 rails: MAW / ETTAN / ED gives MAWETTANED.
Your answer
?Encrypt CODEBREAKER with the rail fence cipher, 3 rails.
Data · encryption ciphers
The pigpen cipher
The pigpen cipher replaces each letter with a symbol.
The key is two noughts-and-crosses grids and two X shapes. Each letter's symbol is the shape of the lines around its position.
Letters in the second grid and second X also get a dot.
Anyone with the key can decode it at once, so it hides messages only from people who don't know the method.
Quick check
?Using the key on screen 7, which letter is drawn as a full square with a dot inside?
Mission check
?Caesar hid his letters in a shifted alphabet. Could you crack it?
Yes. A Caesar cipher has only 25 useful shifts, so a brute-force attack tries them all. Shifting YHQL back by 3 gives VENI, Latin for "I came".
Recap
Big ideas
Compression makes files smaller: less storage, faster transfer, less bandwidth.
Lossless compression rebuilds the original exactly by storing repetition efficiently.
RLE stores each run as a count and a value: 0000011100000011 → 5 0 3 1 6 0 2 1.
Lossy compression permanently removes data for much smaller files.
Encryption turns plaintext into ciphertext with a key so intercepted data can't be read.
Caesar shifts every letter by one key; Vigenère uses a keyword of shifts; rail fence rearranges letters in a zigzag; pigpen swaps letters for symbols.
A cipher with few possible keys, like Caesar, can be cracked by brute force.
🏆
Mini-lesson complete!
⭐⭐⭐
You've worked through Data storage, compression and encryption for Pearson Edexcel International GCSE Computer Science (4CP0). 🎉
Mission 1How can a file shrink but still open exactly as before?
Mission 2Caesar hid his letters in a shifted alphabet. Could you crack it?
Specification points and sources for this lesson are listed at the bottom of the page.
Sources (5)
The specification points and sources behind this lesson.
1 Edexcel International GCSE 4CP0 spec, 3.3.2, 3.3.3
2 Pearson Edexcel International GCSE 4CP0 spec, 3.4.1–3.4.2
3 Suetonius, Life of Julius Caesar 56.6, https://lexundria.com/suet_jul/56.6 ("substitute the fourth letter of the alphabet, namely D, for A, and so with the others")