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

Strengthen Your Cipher with Substitution

At the end of the Cybersecurity: Encryption Intro tutorial, there’s a Your Turn in the Substitution Ciphers page where you created a scrambled_alphabet_cipher script.  This kind of function is a much better defense against brute force attacks.  Instead of testing 93 possible shifts, a brute force attack would have to try decrypting with 26! permutations of the alphabet.  The term 26! is pronounced 26 factorial.  

3! = 3 * 2 * 1 = 6
4! = 4 * 3 * 2 * 1 = 24
5! = 5 * 4 * 3 * 2 * 1 = 120
…
26! = 403,291,461,126,605,635,584,000,000

Wow!  That would be a lot of rearrangements of the alphabet for a brute force algorithm to crack.  Also, who would try to look at all those combinations to find the intelligible text?

Example script: scrambled_alphabet_cipher

  • Enter, name, save, and flash scrambled_alphabet_cipher into a micro:bit.
# scrambled_alphabet_cipher

from microbit import *

# Scrambled alphabet cipher.
def scramble(text, encrypt):
    alpha  = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    crypta = "PTQGMKCRSVEXADZBJFOWYNIHLU"
    result = "
    
    if encrypt is False:
        temp = alpha
        alpha = crypta
        crypta = temp

    for letter in text:
        letter = letter.upper()
        index = alpha.find(letter)
        result = result + crypta[index]

    return result

# The script starts executing statements from here.

sleep(1000)

print("Set your keyboard to CAPS LOCK.")
print()

while True:
    text = input("Enter a CAPS LOCK string: ")
    
    result = scramble(text, True)

    print("scrambled result =", result)
    
    result =  scramble(result, False)
    
    print("unscrambled result =", result)

 

  • If the serial monitor isn’t already open, click the Show serial.
  • Either press CAPS LOCK, or hold the SHIFT key as you type.
  • Type HAPPY into the terminal.
  • Verify that the scrambled result is RPBBL.  That’s the encrypted result.
  • Verify that the unscrambled, decrypted result is HAPPY.

 


Printer-friendly version
Try This: More Combinations
Prev
How the Scrambled Alphabet Cipher Works
Next

DISCUSSION FORUMS | PARALLAX INC. STORE

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

© 2025 Parallax Learn • Built with GeneratePress