Up to this point, the scripts have used simple PINs with three or four binary digits. If the scripts instead use decimal digits, the increase in possible combinations improves the security by making it more time consuming to crack the PIN with brute force.
In this activity, you will use scripts that repeat what you’ve done up to now, but with decimal digits in the 0 through 5 range. Since each digit has six possible values, the number of combinations is:
6 x 6 x 6 = 63 = 216 combinations
- If you are part of a class, and have been assigned a channel, make sure to adjust the script’s channel=7 to your assigned channel before you save and flash the scripts.
- Enter, save, and flash the transmitter decimal_pin_pad_transmitter script into the PIN Pad Transmitter micro:bit.
- Enter, save, and flash the receiver decimal_bank_vault_receiver script into the Bank Vault Receiver micro:bit. Receiver Script (decimal bank vault) is below the Transmitter Script (decimal PIN pad).
- Before continuing, take a look at the decimal_bank_vault_receiver script’s pin = '324' statement. This is the PIN number you will have to enter into the PIN Pad Transmitter micro:bit’s A/B buttons to gain access.
Transmitter Script: decimal_pin_pad_transmitter
# decimal_pin_pad_transmitter from microbit import * import radio radio.on() radio.config(channel=7) pin = '' n = 0 while True: x = len(pin) 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 if button_b.was_pressed(): pin += str(n) n = 0 if len(pin) == 3: radio.send(pin) display.scroll(pin) pin = '' display.clear()
Receiver Script: decimal_bank_vault_receiver
# decimal_bank_vault_receiver # <- change from microbit import * import radio import random radio.on() radio.config(channel=7) pin = '324' # <- change while True: display.show(Image.SQUARE_SMALL) # <- change message = radio.receive() if message: pin_entered = str(message) if pin_entered == pin: radio.send("Access granted.") for n in range(4): display.show(Image.YES) sleep(1000) display.clear() sleep(200) else: radio.send("Access denied.") display.show(Image.NO) sleep(3000) display.clear()
Again, let’s check to make sure each micro:bit is running the correct script.
- Verify that the decimal PIN Pad Transmitter micro:bit has no lights on.
- Verify that the decimal Vault Receiver micro:bit shows a square in the center of its display.
Now, as you press and release the A button, LEDs will light from the top downward. No lights in a column means 0. One light means 1, and so on, up through five lights for 5.
- Enter the correct key like this: A A A B A A B A A A A B.
- Verify that two things happened:
- The decimal PIN Pad Transmitter micro:bit scrolls 3 2 4 across its display.
- The decimal Bank Vault Receiver displays a flashing check mark indicating access granted:
- As in the first round, try some other combinations and make sure that they result in the decimal Bank Vault Receiver displaying an X to indicate access denied.