XOR mixes a number with a key. Doing it again with the same key brings the number back, so one shared key works in both directions.
Most of the secret messages on the internet are locked with a key that both ends already share. The locking step is much like this lesson, only with far bigger numbers.
A computer stores numbers as patterns of bits (0s and 1s). XOR (written ^) compares two numbers bit by bit: where the bits differ the answer has a 1, where they match it has a 0.

7 = 111
5 = 101
7 ^ 5 = 010 = 2
Now the useful part: do it again with the same key and you get the original back. 2 ^ 5 = 7. So the sender computes message ^ key, and the receiver computes received ^ key. One shared key, one operation, both directions.
Make your prediction first. Help opens once you've locked it in.

let key = 5
radio.setGroup(5)
input.onButtonPressed(Button.A, function () {
radio.sendNumber(7 ^ key)
})
radio.onReceivedNumber(function (receivedNumber) {
basic.showNumber(receivedNumber ^ key)
})
Open Show data in the simulator and find the number the radio carried.

let key = 5
radio.setGroup(5)
input.onButtonPressed(Button.A, function () {
radio.sendNumber(7 ^ key)
})
radio.onReceivedNumber(function (receivedNumber) {
basic.showNumber(receivedNumber ^ key)
})

let key = 5
radio.setGroup(5)
input.onButtonPressed(Button.A, function () {
radio.sendNumber(7 ^ key)
})
radio.onReceivedNumber(function (receivedNumber) {
basic.showNumber(receivedNumber ^ key)
})
What number does the radio carry when the sender encrypts 6 with key 3? (6 is 110 in bits and 3 is 011.)
Let B change the key and show it. Set the key the same on both micro:bits, then press A. Then make the keys different. What happens?
B adds one to key (back to 1 after 15) and shows it. Make both micro:bits agree before pressing A.
B changes the key and shows it.
This ticks by itself when your blocks do what is asked.
A variable pin holds 4271; A sends pin ^ key by radio.
On radio received number, show received number ^ key.
Send a four-digit PIN, locked with a shared key, to a second micro:bit that unlocks and shows it.
A door keypad sends a PIN locked with the key; the receiver unlocks it and shows it.
This ticks by itself when your blocks do what is asked.
Students lock and unlock numbers with XOR and a shared key, and meet the weakness of sending the same locked message every time. About 45 minutes.
Open the teacher guide: answers, solutions, slides and a worksheet.
The idea: XOR gives a 1 where two bits differ and a 0 where they match. Doing it twice with the same key returns the original, so one key and one operation work in both directions. This is a shared-key (symmetric) cipher.
Bits: the lesson text shows 7 ^ 5 in bits. If students have not met binary, treat the working as a table to read, not something to learn: the check answers can be found by following the pattern.
Two honest limits: (1) XOR with a short key repeated is breakable; real systems use long keys and better methods. (2) The same message gives the same locked number every time, which the last Make task shows. Both are why the next lessons matter.
XOR undoes itself with the same key, and a wrong key gives a wrong answer, not an error. Ask them to compare the keys on both micro:bits first.
Stretch: Lock each digit of the PIN separately, using a different key digit for each.
Support: Give the sending half complete.
Next: both ends need the same key. How do they agree it without sending it?