Doctor Who and the micro:bit - Mission Decode
Teachers! Before you continue, download the lesson plan, hand-outs and presentation slides for this mission here!
Hi again! The one and only MICROBIT at your service. You really helped us out last time – you made your own Sonic Gadget to help fend off the Dalek menace but we’re not much closer to saving the universe unless we put your Sonic to good use!
Luckily for all of us, the Doctor has been doing some digging into what's going on inside the Dalek's spaceship. He's been there enough times to know the place inside and out, but it seems they've recently changed their network security measures, so getting in has proved... tricky.
He's not turned up empty-handed, though - the Doctor sent over a load of data that was intercepted on its way to and from the spaceship.
I've used my many information sorting subroutines to scan through most of the data - I think it could be our ticket to let me hack in to the battleship remotely. It'll be just like hopping on your neighbour's WiFi.
Translate the flashing lights!
During my scanning of the Doctor's data, I found this really interesting chunk of video data with something... odd about it.
I’ve converted it to a video format Earth's computers can play, it's embedded above. Do you see that flashing square in the video ten seconds in? Very suspicious.
I’m certain that’s some kind of encoded message but I don’t have the memory spare to install an interpreter program for it. Sorry!
Don’t worry though, you can run a backup interpreter program I’ve made using your micro:bit Sonic Gadgets! I’ve put the interpreter .hex file here; right click and choose ‘save as’ to download it.
Using it is easy. Once you have uploaded the interpreter hex file, put the LEDs of your micro:bit against your computer screen, so they fit inside the flashing square. Then play the video and hold it there until the flashing stops.
Then, pull the micro:bit away and take a look at the LEDs. It should have interpreted the message!
There’s a knack to it, so don’t worry if it doesn’t read the message correctly the first time and give it another try.
Receive the Mysterious Signal!
So after reading the flashing lights, we got a message that said ‘Connect to radio’, eh? Whatever secret the Doctor snagged for us, it sure is well protected!
But you’ve already got the answer in your hands – you might not know already, but the micro:bit can send and receive radio signals. I bet if we get a separate micro:bit to connect with the one showing the ‘Connect to Radio’ message, we’ll get another clue.
It’s easy to program Radio functions on your micro:bit using either PXT or Python. For this bit, we'll be using the PXT editor (Don't worry Python fans, there'll be something for you later).
Radio blocks have a special section on the toolbar. To enable radio functions, we need to add a few inside the On Start block.
The 'radio set group' block will change what radio frequency your micro:bit will send out and receive signals on, so setting it to something other than the default (0) is a great way to help keep your messages secret from someone... like those pesky Daleks.
In PXT you can choose between 255 different channels and the interpreter script I had you use earlier has the radio channel set to 132. We’ll also need to set our radio receiver to the same channel.
Next, we’re going to need the On Radio Received block. It comes pre-packaged with a variable to store information in. We’re going to want to look for a string variable, since the interpreter is sending us a message.
And lastly, we want to display that message in a loop. Take the ‘while true’ block from the Loops tab, and place the ‘show string’ block from the Basic tab inside of it. The Variables tab will contain the recievedString block to fit inside the ‘show string’.
If you want test your script without connecting it to the Interpreter just yet, you can test the code inside PXT by adding an ‘on button pressed’ block and a ‘radio send string’ block inside it.
Decipher the access password
Good work – our radio signal receiver has revealed the hidden message. I’ve just tried to use it to access the Dalek space ship but no dice, unfortunately. Scanning through my language banks, it doesn’t mean anything in any languages on Earth… Or on any alien planets, for that matter.
So I can only conclude that this message has been encrypted in some way! There are many ways of encrypting a message to it looks like gibberish to anyone without the decode key, but if I know Dalek security protocol (and trust me, I totally do), a transmission like this probably only has a Caesar Cipher encoding it.
It’s time to write a new script for our Sonic Gadgets! This time, it’ll be a decoding machine! We'll be doing a lot of cool coding tricks here, so we will use the Python editor for this part of the mission.
What's a Cipher?
The Caesar Cipher is a simple encryption technique - altering a message so it can't be read by a random outsider.
When messages are encrypted with a Caesar Cipher, the characters in that message are shifted along by some amount. For example, if the letter 'A' was encrypted by 1, it would become 'B'. If the letter 'Z' was encrypted by 1, it would loop round and become 'A'.
The amount the letters are shifted by is the key to being able to encrypt or decrypt a message using a Caesar Cipher, so it's something you could crack by hand with a little patience. It's possible to make a 'cipher wheel' that represents how many steps shifted a cipher is, making it a little easier to translate an encrypted message back into something readable.
However, to work out what that encrypted word would look like with each of the 26 possible key shifts would take ages by hand, even with the cipher wheel. That's where our micro:bit comes in.
First, we need to understand the algorithm that we need to use. Instead of putting letters around the edge of two disks we can use numbers to represent each character. So 'A' would be represented by 1, 'B' would be represented by 2 and so on. Then, we can add the shift number we want to test, and change the number back into a letter again.
For example, the letter 'C' is represented by 3. We want to shift it by +4, making it 7. Convert that back into letters again and we get 'G'.
Don't worry if that sounds a little confusing, it will all snap into place once we start coding.
Code the Decipher Program!
Like any Python code for the micro:bit, we need to set up all the basic micro:bit module commands with:
from microbit import *
Next, we're going to 'define' our own function. This means we can write an algorithm in advance and give that algorithm a cool name, so we can call for it later without typing it out every time.
Our deciphering script will need two defined functions:
- A function that assigns each letter of the alphabet to a number and can shift it along to a different number
- A function that goes through each letter of the encoded word you're trying to crack and applies the shift.
Copy the following coding sample into your Python editor:
Sweet. Next we need to state what the message we're decoding is.
Please type the encrypted code word you found earlier between the quotation marks.
Last step before we code the input, we set the starting amount of shifts when the micro:bit is turned on, and display the message on the micro:bit before we make any shifts to it.
shift_key = 0
Okay, everything's set. Now we need to code the message shifting along the cipher wheel every time we press the A button. The picture below is our solution on how to do this. To break down how it works:
- While the micro:bit is running, it checks if the A button has been pressed.
- It updates the value of the shift_key variable by one. Since the A button is on the left, pressing it will subtract 1 from the shift key (as if you were turning the cipher wheel to the left)
- The amount the cipher wheel has been shifted is displayed.
- Thew display is cleared, and the shifted version of the encoded message is displayed.
- You can press the A button while the new encoded message is scrolling across to 'interrupt' and move on to the next shifted version, instead of waiting.
You can see the latter half of this code in the image below. If you want to experiment with our version of the decipher script .hex file you can download it here by right clicking and choosing 'Save as'.
Upgrade your Decipher Program and uncover the password!
If you run the program now, you'll be able to start cracking the encrypted password we discovered, but there's a few ways you can make the code more efficient:
- Adding in a B Button command that will rotate the cipher wheel in the other direction (currently the shift_key for the A button decreases by 1, so for the B button it needs to...)
- Adding in a simultaneous A button and B button command that just shows the message with the current shift again without rotating it.
Have you worked out the password?
If you think you have the password, now's the time to see if you got it right. Add the password you've found to this url, replacing the underscore (Note: the password is case-sensitive, so use all capital letters):
If you've got it right, it should lead to a new webpage, and we'll have accessed the Dalek spaceship computer network! I wonder what's on there...?