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 the Decimal Code Works

Node How it Works: decimal_pin_pad_transmitter

Compared to the first binary pin_pad_transmitter script, this decimal version has the same statements, up through x = len(pin).

# decimal_pin_pad_transmitter.py

from microbit import *
import radio

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

pin = ''
n = 0

while True:

    x = len(pin)

 

When button A is pressed to select the next digit, the script remembers that digit by increasing the value of n.  It also represents 0 with no lights, 1 with the row 0 LED on, 2 with the row 1 LED on, and so on, up through 5 with the row 4 LED on.  The if n < 5 block takes care of adding 1 to n and successively turning on each LED in the column.  If all the lights are on and you press A again, the else block takes care of setting n to 0 and turning off all the lights.

    if button_a.was_pressed():
        if n < 5:
            n += 1
            if n is not 0:
                y = n - 1
                display.set_pixel(x, y, 9)
        else:
            for y in range(0, 5):
                display.set_pixel(x, y, 0)
            n = 0

 

Take a close look at if n is not 0 above.  It prevents any lights from turning on when n is 0.  When n is 1, it has to turn on the light in row 0.  Since the row with the light on has an index of one below the value of n, y = n – 1 stores the value of the correct row index in y to turn on the correct LED.  

When button B is pressed, the script has to update the pin string and reset n to 0 so that you can enter the next column.  If button B is pressed to enter a digit in the third column, it also has to send the pin string to the decimal vault micro:bit.  

    if button_b.was_pressed():
        pin += str(n)
        n = 0
        if len(pin) == 3:
            radio.send(pin)
            display.scroll(pin)
            pin = ''
            display.clear()

 

In pin += str(n), the str(n) call returns a string with a single digit character that represents the value n stores.  That character could be ’0’, ’1’, ’2’, ’3’, ’4’, or ’5’.  The pin += part appends that character to the pin string.  When the pin string is appended with the third digit, len(pin) will return 3.  At that point, the if len(pin) == 3 block sends the pin string to the Vault Receiver micro:bit, scrolls the digits across the LED display, resets pin to an empty string, and clears the display.  

How it Works: decimal_bank_vault_receiver

Aside from the comment with the script’s name, only three other lines were changed.  In the original binary version, the script initialized pin to ’011’, then displayed a dot in the center of the LED display.

pin = '011'

while True:

    display.set_pixel(2,2,9)

 

In the decimal version, all that really needed to change was the pin string—from ’011’ to ’324’.  Since there might be some confusion about whether the original binary or updated decimal version of the vault receiver script is running, the single pixel in the center of the binary version was changed to a small square in the center of the decimal version.

pin = '324'

while True:

    display.show(Image.SQUARE_SMALL)

 


Printer-friendly version
Decimal Vault PIN
Prev
Decimal Bank Vault Crack
Next

DISCUSSION FORUMS | PARALLAX INC. STORE

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

© 2025 Parallax Learn • Built with GeneratePress