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: Brute Force Attacks & Defenses

Cybersecurity: Brute Force Attacks & Defenses

How Using the Random Key Works

How It Works: radio_send_images_caesar_key_unknown

This section only explains modifications that make it use a random key and send strings at a slower rate.

Using set key to (pick random (1 to 25)) sets the key equal to a randomly generated integer in the 1 through 25 range. This statement was placed inside the on start block so that it gets executed before the main loop starts sending repeated encrypted messages. That way, the project sets the key value once, and then uses it with every repetition of the forever loop. 

Each time you restart the micro:bit, there is a 1 in 25 chance you will get the same key. Conversely, there is a 24 out of 25 chance that the key will be different.

In the main loop, set packet to caesar(key, packet) makes it so that the main loop repeatedly uses the one key value that was randomly determined before the main loop started repeating.

Pause (6000) is set to 6 seconds to intentionally slow down the broadcast rate and gives the online editor enough time to take a 0.2 s break between each line printed. This will reduce the WebUSB tendency to make printing errors.

How It Works: radio_receive_images_caesar_brute_force

The brute force receiver uses a loop that decrypts and prints the decrypted packet’s result to the terminal with each of the 25 possible keys. The for key in (range start(-1) end (-26) step (-1)) loop repeats the indented-below statements with key set to -1, then -2, -3, and so on up through -25. Each time through the loop, set result to (call caesar (key, packet)) decrypts the packet for that repetition’s key value. Then, serial write line (join (“key: “)(key)(“, result: “) (result)) displays the key and decrypted string for each iteration of the loop. 

Lastly, pause (200) delays before repeating the loop to give the online editor’s WebUSB connection extra time to transfer information to the terminal (since it seems to need it at the time of this writing). After all 25 loop repetitions, serial new line displays an empty line before the forever loop repeats and another 25 keys and decrypted strings are displayed.


Printer-friendly version
Crack a Cipher with Brute Force
Prev
Try This: More Combinations
Next

DISCUSSION FORUMS | PARALLAX INC. STORE

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

© 2025 Parallax Learn • Built with GeneratePress