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

Try This: Generate a Random Cryptabet

It takes a while to well and truly shuffle the characters in an alphabet by hand, so why not use a script?  

  • Enter, name, save, and flash cryptabet_autogenerate
  • If the serial monitor isn’t already open, click Show serial.  
  • Wait while it builds the cryptabet with an approach that kind of resembles a brute force attack!

If you want the scramble to be repeatable, you can add a statement like random.seed(10) anywhere above while n < size:  For each different seed, you will get a different, but repeatable,  result.  Without a manually entered seed value, the micro:bit uses the system timer to get a more random seed to determine the sequence.

Example script: cryptabet_autogenerate

# cryptabet_autogenerate
from microbit import *
import random

sleep(1000)

alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
size = len(alpha)

print("size: ", size)
print("alpha:", alpha)

sleep(1500)

crypta = "

n = 0
while n < size:
    sleep(50)
    r = random.randint(0, size-1)
    c = alpha[r]
    print("r:", r, ", c:", c)
    if crypta.find(c) == -1:
        crypta = crypta + c
        n = n + 1
        print("n:", n, ", crypta:", crypta)

sleep(1000)    
print("crypta:", crypta)
sleep(100)
print()

How It Works

The cryptabet_auto_generator script starts with alpha, which is set to the upper-case alphabet for the sake of example.  It repeatedly generates random numbers in the 0…25 range, and then grabs the character at that index from alpha.  Then, it checks if that character is already in crypta.  If yes, then it discards the character and tries again.  If no, then it appends the character to crypta and starts adding the next character.

Sleep statements were added at various points to give the online editor’s terminal enough time to keep up with the stream of text data.

The script uses the length of the alpha string to build the crypta string.  So there would be no problem using a custom alphabet, like alpha = “vLR{}:,’01234 56789”, for example.  That particular alphabet would support dictionaries from the Terminal Control – Go Wireless activity.

 


Printer-friendly version
How the Scrambled Alphabet Cipher Works
Prev
Your Turn: Strengthen Previous Apps
Next

DISCUSSION FORUMS | PARALLAX INC. STORE

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

© 2025 Parallax Learn • Built with GeneratePress