← International GCSE Computer Science · Edexcel · GCSE Computer Science revision
⭐ 0
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.

  1. Mission 1How can a file shrink but still open exactly as before?
  2. Mission 2Caesar hid his letters in a shifted alphabet. Could you crack it?
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

Runs of repeated pixels6 W3 B4 Wrebuilt exactly13 pixels
  • 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 encoding000005 01113 10000006 0112 1countvalue16 bits become 4 pairs
  • Run length encoding (RLE) replaces each run of repeated data with a pair: how many times it repeats, then the value.
  • Each pair is a count and a data value.
  • Example: 0000011100000011 becomes 5 0 3 1 6 0 2 1.
  • 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

Lossless and lossyOriginaloriginal fileLosslessrebuilt exactlyLossydata removed for good
  • 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?
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

Caesar shift 3PlainCipherADBECFDGEHFIGJHKILJMKNLOMPPlainCipherNQORPSQTRUSVTWUXVYWZXAYBZCShift 3
  • 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

Vigenère cipherPlaintextATTACKKeyLEMONLShift11412141311CiphertextLXFOPV
  • 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

Rail fence cipherMEETATDAWNRail 1: MAWRail 2: ETTANRail 3: EDCiphertext: MAWETTANED
  • 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

Pigpen keyABCDEFGHIJKLMNOPQRSTUVWXYZExamplesAEJ
  • 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?
Which letter?
Mission check

?Caesar hid his letters in a shifted alphabet. Could you crack it?
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). 🎉

  1. Mission 1How can a file shrink but still open exactly as before?
  2. Mission 2Caesar hid his letters in a shifted alphabet. Could you crack it?

Your stars: 0 / 0

Next: more International GCSE Computer Science · Edexcel lessons and games on the International GCSE Computer Science · Edexcel page.

📣 Smashed it? Share your score

Challenge a mate to beat your stars, or show a parent how you got on.

→ Back to International GCSE Computer Science · Edexcel

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. 1 Edexcel International GCSE 4CP0 spec, 3.3.2, 3.3.3
  2. 2 Pearson Edexcel International GCSE 4CP0 spec, 3.4.1–3.4.2
  3. 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")
  4. 4 Ciphers Online, "Pigpen Cipher", https://ciphersonline.com/codes-and-alphabets/pigpen (standard Masonic key: A–I grid, dotted J–R grid, S–V X, dotted W–Z X); pigpen LaTeX font documentation, https://tex.org.uk/fonts/pigpen/doc/pigpendoc.pdf (X arms: S/W top, T/X left, U/Y right, V/Z bottom)
  5. 5 /home/claude/cs/work/N9-checks.py