Texting with Terminals: Unencrypted vs. Encrypted

Another activity that was vulnerable to sniffing attacks was the Bidirectional Texts application from Cybersecurity: Radio Basics.  In this activity, you will add an ASCII shift cipher to encrypt and decrypt the text communication.  


  • Reopen terminal_chat_through_microbits from Bidirectional Texts.  (If you did not save it, go back to the activity and follow the instructions to get it up and running.)
  • Make sure that one micro:bit is running a transceiver A version, and the other is running a transceiver B version.
  • Make sure you can exchange unencrypted messages from one terminal to another through the radio-connected micro:bit modules.
  • Careful what you type, anybody else can see what you write!

Next, let’s encrypt micro:bit transceiver A’s data and see what it looks like in micro:bit transceiver B’s terminal.  

  • Leave micro:bit transceiver B as-is.
  • Load terminal_chat_through_microbits_encrypted_A into micro:bit transceiver A only.

Transceiver Script: terminal_chat_through_microbits_encrypted_A

# terminal_chat_through_microbits_encrypted_A.py
# learn.parallax.com/cyberbot
# Copyright Parallax Inc 2020 under MIT license

from microbit import *
import radio

''' Function converts plaintext to ciphertext using key '''
def ascii_shift(key, text):
    result = ""
    for letter in text:
        ascii = ( ord(letter) + key - 32 ) % 94 + 32
        result = result + chr(ascii)
    return result

''' Script starts from here... '''



print("micro:bit transceiver A")

text = input("Enter key: ")
key = int(text)

print("Type messages, press enter to send.")
print("Received messages will also be displayed.")

while True:
    if uart.any():
        tx = input("Send: ")
        tx = ascii_shift(key, tx)
    message = radio.receive()
    if message:
        message = ascii_shift(-key, message)
        print("Receive: ", message)
  • Click the Open Serial button in the browsers, and reset the micro:bit modules.
  • In micro:bit transceiver A:, you will need to enter a key value between 1 and 25.  This example uses 19.
  • Try typing this into micro:bit transceiver A: Hello there!  Can you read this?

What do you see in micro:bit transceiver B’s terminal?  This is what an attacker trying to use sniffing would see when you send the encrypted message.



  • Save terminal_chat_through_microbits_encrypted_A as terminal_chat_through_microbits_encrypted_B.
  • Update the script’s name comment, and change print("micro:bit transceiver A") to print("micro:bit transceiver B").
  • Save the modified script, and flash it into micro:bit transceiver B.
  • Make sure to enter the same key you used into micro:bit transceiver A.
  • Re-test with Hello there!  Can you read this?  Also try replying Yes I can! from micro:bit transceiver B.