In a way, dictionary data looks kind of cryptic to begin with. But, without actual encryption, it would make it very easy for attackers to know where your cyber:bot is going in a contest.
This activity will show you how to encrypt data for the countdown app from the Cybersecurity: Radio Data [1] tutorial’s Send and Receive Packets [2] activity. Make sure you understand it!
After that, your task will be to follow the same steps to encrypt the terminal controlled cyber:bot app from the Cybersecurity: Navigation Control from a Keyboard [3] tutorial’s Terminal Control — Go Wireless! [3] Activity.
When you have a working radio data app, it only takes three steps to update the script so that it transmits encrypted data. Likewise, it only takes three steps to update a receiver script to decrypt the data.
Transmitter:
Receiver:
Before adding encryption, it’s best to make sure the original app is working.
Now that you’ve got the original app working, follow the steps to update the scripts to send and receive encrypted data. Again, it’s important to follow the steps because you’re on your own when it comes to encrypting the wireless keyboard cyber:bot control.
from microbit import * import radio # Step 1: Add the cipher function below the transmitter # script’s import statements. (6 statements) def ascii_shift(key, text): result = "" for letter in text: ascii = ( ord(letter) + key - 32 ) % 94 + 32 result = result + chr(ascii) return result # Step 2: Set an encryption key with a statement like key = 5. key = 5 radio.on() radio.config(channel=7,length=50) sleep(1000) print("Countdown App") print("micro:bit sender") while True: text = input("Enter countdown start: ") value = int(text) message = input("Enter message after countdown: ") dictionary = { } dictionary['start'] = value dictionary['after'] = message packet = str(dictionary) print("Send: ", packet) # Step 3: Call the cipher function to encrypt the data # before sending the packet. packet = ascii_shift(key, packet) radio.send(packet) print()
# countdown_receiver_encrypted.py from microbit import * import radio # Step 1: Add the cipher function below the transmitter # script’s import statements. (6 statements) def ascii_shift(key, text): result = "" for letter in text: ascii = ( ord(letter) + key - 32 ) % 94 + 32 result = result + chr(ascii) return result # Step 2: Set a key to decrypt with a statement like key = -5. key = -5 radio.on() radio.config(channel=7,length=50) sleep(1000) print("Countdown App") print("micro:bit receiver\n") while True: packet = radio.receive() if packet is not None: # Step 3: Call the cipher function to decrypt the data # after receiving/before using the packet. packet = ascii_shift(key, packet) print("Receive: ", packet) print() print("Parse: ") dictionary = eval(packet) value = dictionary['start'] message = dictionary['after'] print("value = ", value) print("message = ", message, "\n") while value >= 0: print(value) sleep(1000) value = value - 1 print(message) print()
By changing one print statement and adding another, you can monitor and compare the plaintext and ciphertext versions of the packets.
# Transmitter Excerpt packet = str(dictionary) # print("Send: ", packet) print("packet: ", packet) # <- change # Step 3: Call the cipher function to encrypt the data # before sending the packet. packet = ascii_shift(key, packet) radio.send(packet) print("Encrypted message: ", packet) # <- add print()
# Receiver Excerpt packet = radio.receive() if packet is not None: print("Receive encrypted: ", packet) # <- add # Step 3: Call the cipher function to decrypt the data # after receiving/before using the packet. packet = ascii_shift(key, packet) print("packet: ", packet) # <- change print()
Up to this point, you just finished adding encryption to the countdown app from the Cybersecurity: Radio Data [2] tutorial’s Send and Receive Packets [2] activity. Now, let’s apply the same technique to the wireless cyber:bot keyboard control app from the Cybersecurity: Navigation Control from a Keyboard [5] tutorial’s Terminal Control — Go Wireless! [5] activity. If you can do this, you will have a level of protection against attackers in future cyber:bot competitions.
Links
[1] http://learn.parallax.com/tutorials/robot/cyberbot/cybersecurity-radio-data
[2] http://learn.parallax.com/tutorials/robot/cyberbot/cybersecurity-radio-data/send-and-receive-packets
[3] https://learn.parallax.com/tutorials/robot/cyberbot/cybersecurity-navigation-control-keyboard/terminal-control-%E2%80%94-go-wireless
[4] https://learn.parallax.com/tutorials/robot/cyberbot/cybersecurity-radio-data/send-and-receive-packets
[5] http://learn.parallax.com/tutorials/robot/cyberbot/cybersecurity-navigation-control-keyboard/terminal-control-%E2%80%94-go-wireless-1
[6] http://learn.parallax.com/tutorials/robot/cyberbot/cybersecurity-navigation-control-keyboard/terminal-control-%E2%80%94-go-wireless
[7] http://learn.parallax.com/tutorials/robot/cyberbot/cybersecurity-navigation-control-keyboard/terminal-control-%E2%80%94-go-wireless-6
[8] https://learn.parallax.com/tutorials/robot/cyberbot/cybersecurity-navigation-control-keyboard/terminal-control-%E2%80%94-go-wireless-1
[9] https://learn.parallax.com/tutorials/robot/cyberbot/cybersecurity-encryption-intro/ascii-and-other-simple-ciphers