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

Try This: Sniffing without Errors

The sniffing receiver script running radio_receive_images threw an exception when it tried to look up getattr(Image, “KDSSB”).  If the string was not encrypted, it would be “HAPPY”, which would work just fine.  

  • In the browser connected to the sniffer micro:bit:
    • Comment the radio_receive_images  script’s display.show(getattr(Image, packet)) statement by adding the # symbol to the left of it.
    • Change the project name to radio_receive_images_sniffer, and then Save. 
    • Click Send to micro:bit to flash the modified script into the sniffer micro:bit.

Can you see the data in the serial monitor now?  

Your Turn – Sniffing with Exception Handling

Instead of commenting display.show in radio_receive_images_sniffer, you can add exception handling code.  That way, your micro:bit’s display will immediately display unencrypted images, and tell you if the data is not a valid image without halting because of an exception.    

  • Use techniques from Exception Handling Primer to prevent an encrypted image string from freezing your application.  

Can you match the serial monitor output shown by the sniffer below?  Whenever the string does not represent a valid image, it prints: packet is not an image string.

How it Works

Both the transmitter and receiver scripts have a caesar() function added above radio.on().  This function was developed step-by-step in Encryption Intro and calling the function was introduced in Caesar Cipher in a Function.   Once your script has the caesar() function at its disposal, all it has to do is call it to encrypt single upper-case word strings.  For example, if packet contains the string to encrypt, packet = caesar( 3, packet ) uses a key of 3 to encrypt the word in packet.  To decrypt, use the negative key value with packet = caesar( -3, packet ).

Remember from the previous activity that packet contains either “HAPPY”, “SAD”, or “ANGRY” strings.  In radio_send_images_caesar, it displays the packet before encrypting with print(“packet:”, packet).  Then, it sends the packet through the Caesar cipher with packet = caesar(3, packet).  Next, print(“Send encrypted:”, packet) prints the ciphertext version of the packet to the serial monitor.  For example, after the caesar(3, packet) call, HAPPY becomes KDSSB.

        print("packet:", packet)
        packet = caesar(3, packet)
        print("Send encrypted:", packet)
        radio.send(packet)
        sleep(2500)

When the intended receiver’s radio.receive call returns an encrypted packet, it should look the same as the transmitter’s encrypted packet.  To decrypt, simply call the caesar function with the negative of the key used to encrypt.  Since the key was 3 to encrypt, it has to be -3 to decrypt.  That’s why the intended receiver script’s packet = caesar(-3, packet) has the negative value of the transmitter’s key.

    packet = radio.receive()

    if packet:
        print("Receive encrypted:", packet)
        packet = caesar(-3, packet)
        print("packet:", packet)
        display.show(getattr(Image, packet))

 


Printer-friendly version
Share Something Personal – Encrypted!
Prev
Texting with Terminals: Unencrypted vs. Encrypted
Next

DISCUSSION FORUMS | PARALLAX INC. STORE

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

© 2025 Parallax Learn • Built with GeneratePress