Skip to content
Parallax Learn

Parallax Learn

  • Welcome
  • Tutorials
        • Tutorial Series head tag

          Tutorial Series
        • Tutorial Series

          The special, classroom-ready series pages are organized collections of tutorials for our most popular hardware and/or languages. The tutorials for each topic are conveniently accessible from a single page, shown in the order it is recommended that they be completed.
        • Robotics Series Head tag

          Robotics Series
        • Robotics Series

          • Artificial Intelligence
          • Cybersecurity: Radio Data tutorialCybersecurity
          • cyber:bot + Python
          • cyber:bot + MakeCode
          • Boe-Bot Tutorial SeriesBoe-Bot
          • Arduino Shield-Bot
          • ActivityBot with C TutorialsActivityBot + C
          • ActivityBot with BlocklyProp Tutorial SeriesActivityBot + BlocklyProp
          • Scribbler 3 Tutorial SeriesScribbler 3
        • Electronics & Programming Series Head tag

          Electronics & Programming Series
          • BS2 Board of Education Tutorial SeriesBS2 Board of Education
          • Propeller C-Language BasicsPropeller C Basics
          • FLiP Try-It Kit C Tutorial SeriesFLiP Try-It Kit + C
          • FLiP Try-It Kit BlocklyProp TutorialsFLiP Try-It Kit + BlocklyProp
          • Badge WX Tutorial SeriesBadge WX
          • Propeller BlocklyProp Basics and ProjectsPropeller BlocklyProp Basics
          • View All Tutorial Series »
        • Browse Tutorials
        • Browse Tutorials

          Individual tutorials sorted by robot or kit, and language.
        • By Robot or Kit
          • ActivityBot
          • SumoBot WX
          • Boe-Bot
          • Shield-Bot
          • cyber:bot
          • Badge WX
          • ELEV-8
          • ARLO
        • By Language
        • By Language

          • Propeller C
          • Arduino
          • BlocklyProp
          • PBASIC
          • Python
          • MakeCode
          • View All Tutorials »
  • Educators
  • Reference
  • Downloads
  • Home
  • All Courses
  • Cybersecurity: Sniffing Attacks and Defenses

Cybersecurity: Sniffing Attacks and Defenses

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 serial monitor 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 serial monitor.  

  • Leave micro:bit transceiver B as-is.
  • In the browser connected to micro:bit transceiver A:
    • Change the project name from terminal_chat_through_microbits to terminal_chat_through_microbits_encrypted_A.  
    • Update the script to match the one below, and then Save it. 
    • Click Send to micro:bit. 
  • Make sure to leave micro:bit transceiver B unchanged, running the micro:bit Transceiver B version of the original terminal_chat_through_microbits script.

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... '''

radio.on()
radio.config(channel=7)

sleep(1000)

print("micro:bit transceiver A")
print()

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

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

while True:
    if uart.any():
        tx = input("Send: ")
        tx = ascii_shift(key, tx)
        radio.send(tx)
    message = radio.receive()
    if message:
        message = ascii_shift(-key, message)
        print("Receive: ", message)
  • Make sure the serial monitor is open in both browsers.  (Click Show serial to open if needed.)
  • In micro:bit transceiver A’s browser, 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 serial monitor?  This is what an attacker trying to use sniffing would see when you send the encrypted message.

Next, let’s make it so that micro:bit transceiver B can exchange encrypted messages with micro:bit transceiver A.

  • Repeat the steps you just did for micro:bit transceiver A, but this time, follow those steps in the browser connected to micro:bit transceiver B.
  • Re-test in micro:bit transceiver A’s serial monitor with Hello there!  Can you read this?  Also try replying Yes I can! from micro:bit transceiver B’s serial monitor.

 


Printer-friendly version
Try This: Sniffing without Errors
Prev
How Encrypted Texting Works
Next

DISCUSSION FORUMS | PARALLAX INC. STORE

About | Terms of Use | Feedback: learn@parallax.com | Copyright©Parallax Inc. 2024

© 2025 Parallax Learn • Built with GeneratePress