A checksum is a small number worked out from a message and sent with it. If the number the receiver works out is different, the message was damaged or changed on the way.
A bar code, a bank card number and a downloaded file all carry a small check number. If one digit is wrong, the scanner or the browser notices and refuses to trust it.
Radio can garble a message (a bit flips in the air), and a message can be changed on purpose. Encryption keeps a message private; it does not tell you it is unchanged. A checksum is the tool for that.
The sender works out a small number from the message (here: add up each letter's place in the alphabet, keep the last digit) and sends it with the message. The receiver works it out again. If the two differ, something changed.
send value sends a name and a number together (Agreeing a key in the open). Here the name is the message itself and the number is its checksum, so each message can be 8 characters at most: a longer one is cut short on the way and fails its own checksum.
Make your prediction first. Help opens once you've locked it in.

let ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
function checksum(message: string): number {
let total = 0
for (let i = 0; i < message.length; i++) {
total += ALPHABET.indexOf(message.charAt(i))
}
return total % 10
}
radio.setGroup(5)
input.onButtonPressed(Button.A, function () {
radio.sendValue("HELLO", checksum("HELLO"))
})
input.onButtonPressed(Button.B, function () {
radio.sendValue("HELLP", checksum("HELLO"))
})
radio.onReceivedValue(function (name, value) {
if (checksum(name) == value) {
basic.showString(name)
} else {
basic.showIcon(IconNames.No)
}
})
B pretends the message was damaged on the way: the text changed but the checksum is still the old one.

let ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
function checksum(message: string): number {
let total = 0
for (let i = 0; i < message.length; i++) {
total += ALPHABET.indexOf(message.charAt(i))
}
return total % 10
}
radio.setGroup(5)
input.onButtonPressed(Button.A, function () {
radio.sendValue("HELLO", checksum("HELLO"))
})
input.onButtonPressed(Button.B, function () {
radio.sendValue("HELLP", checksum("HELLO"))
})
radio.onReceivedValue(function (name, value) {
if (checksum(name) == value) {
basic.showString(name)
} else {
basic.showIcon(IconNames.No)
}
})

let ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
function checksum(message: string): number {
let total = 0
for (let i = 0; i < message.length; i++) {
total += ALPHABET.indexOf(message.charAt(i))
}
return total % 10
}
radio.setGroup(5)
input.onButtonPressed(Button.A, function () {
radio.sendValue("HELLO", checksum("HELLO"))
})
input.onButtonPressed(Button.B, function () {
radio.sendValue("HELLP", checksum("HELLO"))
})
radio.onReceivedValue(function (name, value) {
if (checksum(name) == value) {
basic.showString(name)
} else {
basic.showIcon(IconNames.No)
}
})
What is the checksum of KEY? (K is 10, E is 4, Y is 24. Add them and keep the last digit.)
Mix a secret key into the checksum. Both micro:bits know it, and nobody else does, so only they can work out a matching number.
Make a variable secretKey = 7, and start total from secretKey instead of 0.
The checksum starts from a secret key.
This ticks by itself when your blocks do what is asked.
Make a message checker: the receiver shows a tick for a good message and a cross for a bad one, and A+B shows how many bad messages have arrived.
A sends MEET with its checksum; B sends a damaged MEAT with MEET's checksum.
On receiving, show a tick when the checksum matches; otherwise add one to bad and show a cross. A+B shows bad.
A sends a good message and B a damaged one; the receiver shows a tick or a cross, and counts the bad ones.
This ticks by itself when your blocks do what is asked.
Students send messages with a checksum, see the receiver reject a changed one, and learn why a keyed checksum is needed against deliberate changes. About 45 minutes.
Open the teacher guide: answers, solutions, slides and a worksheet.
The idea: privacy (encryption) and integrity (nobody changed it) are different jobs. A checksum is a small number worked out from the message and sent with it; a mismatch means the message changed.
Everyday picture: counting the cards when you hand over a pack. Say there are 52; if the receiver counts 51, something is missing. Where it breaks: if someone swaps a card for another, the count is still 52.
Honest limits: this checksum is deliberately simple. It ignores the order of letters (Investigate task 2), only has ten values (a changed message matches by chance one time in ten), and when the method is public anyone can make a matching one (task 3). Real systems use hash functions and a keyed checksum called a MAC.
Code: radio.sendValue(name, value) sends text and a number together, so the message and its checksum travel in one packet. The name is limited to 8 characters.
A plain checksum catches accidents but not deliberate changes. Ask what an attacker would need to make a changed message pass.
Stretch: Make the checksum depend on order: add the letter's place times its position in the message.
Support: Give the receiving checker complete and ask students to write only the sender.
Next: prove who is sending, not just that the message is whole.