- Features
- Video
- Description
- Prerequisite Skills
- Learned Skills
- Materials
- Getting Familiar
- Helper class provided by the helpful folks at microbit-playground
Features
- Estimated Time: 1 Hour (basic) - 4 Hours (advanced)
- Appropriate Grades: 6-12
- **Topic Alignment ** (Limited, Medium, High)
- GenCyber Cybersecurity First Principles:
GenCyber CFPs | Alignment |
---|---|
Data Hiding | H |
Least Privilege | L |
Abstraction | M |
Domain Separation | L |
Resource Encapsulation | M |
Simplicity | H |
Modularity | M |
Process Isolation | H |
Layering | H |
Minimization | H |
- GenCyber Cybersecurity Concepts:
GenCyber CCs | Alignment |
---|---|
Defense in Depth | H |
Confidentiality | H |
Integrity | L |
Availability | H |
Think Like an Adversary | H |
Keep It Simple | M |
[ Video](https://youtu.be/rfwrJqGM-fw "Digital Lockpick Lab")
You are a secret agent tasked with recovering stolen information from a secure lock box. But there's a problem, there is no physical key to the lock box. You learn that the criminal uses a cryptographic electronic key to unlock this box and sends that key over the radio. Your mission is to attempt to guess the secret key and retrieve the information from the box. There will be 3 lock boxes with progressively harder keys that you must discover. Through this process you will discover how electronic keys work similar to many real-world situations (i.e. office building key cards). This scenario is also designed to make you think about radio signals and how their wireless nature lends to easy eavesdropping of information. Description
Some familiarity with either Make::Blocks or MicroPython languages for the MicroBit. * Micro::Bit Coding Options * [Click here for JavaScript/Blocks Web IDE] ( Prerequisite Skillshttps://makecode.microbit.org) * Click here for MicroPython Web IDE
Learned Skills
-
Servo Motor Basics
* Click here for information on servo motors
* Click here for Micro::Bit servo basics -
Radio Signal Basics
* One "super secure" lock box * One MicroBit "key" Materials
We are going to be using two components of the MicroBit for this activity, the radio and the servo motor controlling capabilities of the MotoBit extension board. Click on the links below to see a short piece of example code related to these two components in both MicroPython and Javascript/Blocks. Getting Familiar
Control Servo(MicroPython)
from microbit import *Helper class provided by the helpful folks at microbit-playground
class Servo:
""" A simple class for controlling hobby servos. Args: pin (pin0 .. pin3): The pin where servo is connected. freq (int): The frequency of the signal, in hertz. min_us (int): The minimum signal length supported by the servo. max_us (int): The maximum signal length supported by the servo. angle (int): The angle between minimum and maximum positions. Usage: SG90 @ 3.3v servo connected to pin0 = Servo(pin0).write_angle(90) """ def __init__(self, pin, freq=50, min_us=600, max_us=2400, angle=180): self.min_us = min_us self.max_us = max_us self.us = 0 self.freq = freq self.angle = angle self.analog_period = 0 self.pin = pin analog_period = round((1/self.freq) * 1000) # hertz to miliseconds self.pin.set_analog_period(analog_period) def write_us(self, us): us = min(self.max_us, max(self.min_us, us)) duty = round(us * 1024 * self.freq // 1000000) self.pin.write_analog(duty) self.pin.write_digital(0) # turn the pin off def write_angle(self, degrees=None): degrees = degrees % 360 total_range = self.max_us - self.min_us us = self.min_us + total_range * degrees // self.angle self.write_us(us)
Servo(pin16).write_angle(0) # Turn motor once Serve(pin16).write_angle(95) # Turn motor again
Control Radio(MicroPython)
from microbit import * import radioradio_group = 1 #number of radio frequency to use radio.on() radio.config(power=7,channel=radio_group) radio.send("Hello")
1. Decide which language you would like to use for this project and navigate to the project code listed in either Setupthe python folder of the supplied code or the javascript/blocks folder. 2. Load your online IDE of choice with the code for the basic-lockbox program. If you have not already read or watched our tutorials on [programming in python or blocks, or on copying the code onto the MicroBit, please check out our instructions wiki. 3. Flash the basic-lockbox code onto the MicroBit included in the lockbox. Then repeat the process for the code for basic-key, but flash this code onto the MicroBit you will use as the key.
Below is listed sections of code for a very basic lockbox that can be opened multiple ways. First, pressing the A/B buttons will unlock the box (not very secure but remember this is our starter box). Secondly, this box will also open if the binary encoding of the number 5 ("0101") is sent over the radio using radio channel 1.
Here we see the beginning of the program, where the microbit initializes the radio group("channel"), then tells the lock to move to position 0, and finally shows us the sprite "No".
//initial setup of the block
radio.setGroup(1)
let position = 0
pins.digitalWritePin(DigitalPin.P16, position)
basic.showIcon(IconNames.No)
Now, in order to unlock the box using the buttons we must tell the microbit to listen for the "On-Click" event that triggered every time the physical button is pushed. Since we initially set the position of our lock to 0, we say that pressing the button A will unlock the box by telling the lock to move to position 95 which is our unlocked position. ?What does the code for the B button which closes the box look like?
//listen for a click event, then un/lock box
input.onButtonPressed(Button.A, () => {
basic.showString("A")
position = 95
pins.servoWritePin(AnalogPin.P16, position)
basic.pause(100)
})
And now we show the code responsible for listening for a key to come over the radio to unlock the box. If the string that is received is equal to the secret key string then we will either lock or unlock the box, depending on the position that the lock is already in.
radio.onDataPacketReceived(({ receivedString }) => {
if (receivedString == "0101") {
if (position == 160) {
position = 20
} else {
position = 160
}
pins.servoWritePin(AnalogPin.P16, position)
}
})
### Easy Lockbox Crack The Lock!
Click here for solution.
Solution hereMedium Lockbox
Click here for solution.
The medium difficulty lockbox requires two wireless keys. First key("0101") must be sent over radio group 2, and then the second key("1001") must be sent over radio group 5.Hard Lockbox
Click here for solution.
The hard lockbox expects the key("100110") but advances its radio group by 1 every 15 seconds until it reaches the maximum radio group and then begins again at zero. Good luck catching it!* Were other people's keys opening your safe? Why is that? How do you prevent that? * Can you think of a better way to secure your lockbox? If so, implement that in the language of your choosing and challenge your partners to crack it! * Use both languages, either MicroPython for the lock box and Javascript/Blocks for the key or vice-versa. Next Steps
The GenCyber Wyoming COWPOKES program is supported by the National Security Agency and the National Science Foundation through Award #H98230-18-1-0095. Any opinions, findings, and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the National Science Foundation, the National Security Agency, or the U.S. government.