Source: https://mokxi.com/learn/path/compression-and-checksums
Updated: 2026-11-20

All paths

# Compression, encoding and checksums

Get a space probe's telemetry and pictures home over a noisy link, in Python on a Raspberry Pi: bits and bytes, run length and Huffman coding, Base64, parity, checksums and CRC-32, ending in a file transfer that survives the noise.

Raspberry Pi 4 Model B Free 7 lessons 6 h 4 chapters 2,515 XP Coding · Advanced +250 XP

0 of 7 done

Start the course free Bits and bytes Lesson plan for teachers

What you will build

## 3 projects, built step by step

7 lessons in 4 chapters, about 6 hours on a simulated Raspberry Pi 4 Model B. Free, in your browser, every step checked by the simulator.

Chapter 1 project

### Run length

The simplest compression there is: a picture of space is mostly black, so say "37 dark pixels" instead of listing them. Runs, packing them into bytes, decoding to prove nothing was lost, and the input that makes it worse than nothing.
Open it in the simulator

Chapter 2 project

### Base64

Some links only carry text: email, JSON, a URL, an old radio modem. Base64 turns any bytes into 64 safe characters, 3 bytes to 4 at a time. Write the encoder and decoder from the bits up, with padding, and check them against Python's own.
Open it in the simulator

Chapter 3 project

### CRC checks

The check inside Ethernet, ZIP, PNG and spacecraft links: a cyclic redundancy check is the remainder of a polynomial division done with XOR. Write CRC-8 and CRC-32 bit by bit, prove CRC-32 against binascii, speed it up with a table, and test it against a thousand noisy frames.
Open it in the simulator

The map

## Chapter by chapter

Each lesson opens when the one before it is done, and each chapter ends in a project.

Chapter 1

## Bytes

What the probe sends, packed tight, and the simplest compression.

Open 250 XP

### Bits and bytes

Everything a space probe sends home is bytes. Text as bytes, binary and hex, packing telemetry into 5 bytes instead of 11 with struct, and eight on-off flags squeezed into a single byte with shifts and masks.

0 of 5 steps

Start What is in it

Project Locked 500 XP

### Run length

The simplest compression there is: a picture of space is mostly black, so say "37 dark pixels" instead of listing them. Runs, packing them into bytes, decoding to prove nothing was lost, and the input that makes it worse than nothing.

0 of 5 steps

4 questions, graded as you go.

Chapter 2

## Codes

Shorter codes for common letters, and safe characters for any bytes.

Locked 250 XP

### Huffman

Give common letters short codes and rare ones long codes: count letters, build a Huffman tree with a priority queue, encode a status report in far fewer than 8 bits a letter, and decode it by walking the tree.

0 of 5 steps

Project Locked 500 XP

### Base64

Some links only carry text: email, JSON, a URL, an old radio modem. Base64 turns any bytes into 64 safe characters, 3 bytes to 4 at a time. Write the encoder and decoder from the bits up, with padding, and check them against Python's own.

0 of 5 steps

4 questions, graded as you go.

Chapter 3

## Checks

Catch the bit flips: parity, checksums and the CRC.

Locked 250 XP

### Parity and checksums

Space is noisy, and a flipped bit turns -12 into -76. Simulate the link with seeded bit flips, catch single flips with a parity bit, watch two flips sneak past, then add a checksum, find its blind spot, and close it with Fletcher's checksum.

0 of 5 steps

Project Locked 500 XP

### CRC checks

The check inside Ethernet, ZIP, PNG and spacecraft links: a cyclic redundancy check is the remainder of a polynomial division done with XOR. Write CRC-8 and CRC-32 bit by bit, prove CRC-32 against binascii, speed it up with a table, and test it against a thousand noisy frames.

0 of 5 steps

4 questions, graded as you go.

Chapter 4

## Project

A picture home, intact.

Locked 265 XP

### Project: a reliable file transfer

Bring the course together and get a picture home over a link that corrupts a third of everything: frames with a sequence number and a CRC-32, a receiver that rejects bad ones, stop-and-wait resends until every frame arrives, run length compression to send fewer frames, and lamps that show each frame land.

0 of 6 steps

4 questions, graded as you go.

Syllabus

## Every lesson in the course

All 7 lessons, in order, each with what it covers. Any of them opens in the editor right away.

Chapter 1

### Bytes

- Bits and bytes Everything a space probe sends home is bytes. Text as bytes, binary and hex, packing telemetry into 5 bytes instead of 11 with struct, and eight on-off flags squeezed into a single byte with shifts and masks.
- Run length The simplest compression there is: a picture of space is mostly black, so say "37 dark pixels" instead of listing them. Runs, packing them into bytes, decoding to prove nothing was lost, and the input that makes it worse than nothing.

Chapter 2

### Codes

- Huffman Give common letters short codes and rare ones long codes: count letters, build a Huffman tree with a priority queue, encode a status report in far fewer than 8 bits a letter, and decode it by walking the tree.
- Base64 Some links only carry text: email, JSON, a URL, an old radio modem. Base64 turns any bytes into 64 safe characters, 3 bytes to 4 at a time. Write the encoder and decoder from the bits up, with padding, and check them against Python's own.

Chapter 3

### Checks

- Parity and checksums Space is noisy, and a flipped bit turns -12 into -76. Simulate the link with seeded bit flips, catch single flips with a parity bit, watch two flips sneak past, then add a checksum, find its blind spot, and close it with Fletcher's checksum.
- CRC checks The check inside Ethernet, ZIP, PNG and spacecraft links: a cyclic redundancy check is the remainder of a polynomial division done with XOR. Write CRC-8 and CRC-32 bit by bit, prove CRC-32 against binascii, speed it up with a table, and test it against a thousand noisy frames.

Chapter 4

### Project

- Project: a reliable file transfer Bring the course together and get a picture home over a link that corrupts a third of everything: frames with a sequence number and a CRC-32, a receiver that rejects bad ones, stop-and-wait resends until every frame arrives, run length compression to send fewer frames, and lamps that show each frame land.

Kits

## Build it on your bench too

Every lesson runs in the simulator with nothing to buy. When you want the real thing, these kits have the parts.

Have a kit already?

### Find your kit

Pick the starter kit you own and run every lesson in its manual with the same parts on the same pins.
See every kit

Questions

## About Compression, encoding and checksums

Is Compression, encoding and checksums free?

Yes. All 7 lessons of Compression, encoding and checksums are free and run in your browser, with nothing to install and no parts to buy before you start.

Do I need a real Raspberry Pi 4 Model B?

No. Every lesson runs on a simulated Raspberry Pi 4 Model B with its parts on the canvas, and the simulator checks each step as you go. When you want to build it for real, the same wiring and code work on a real board.

How long does Compression, encoding and checksums take?

About 6 hours: 7 lessons in 4 chapters, each one a few short steps. Your progress is kept, so you can stop after any lesson and pick up where you left off.

What will I build?

Each chapter ends in a project that puts it together: Run length, Base64 and CRC checks.

Where do I start?

With "Bits and bytes", and each lesson builds on the one before it. New to circuits? Electronics basics is the course that starts from zero.
