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: Encryption Intro

Cybersecurity: Encryption Intro

Substitution Ciphers

Another encryption example is the substitution cipher. With a substitution cipher, each character in an alphabet maps to a cryptabet with different characters in the same position. The simplest example of this is the Atbash or reverse-alphabet cipher. 

Alphabet: ABCDEFGHIJKLMNOPQRSTUVWXYZ
Cryptabet: ZYXWVUTSRQPONMLKJIHGFEDCBA

Example project: substitution_cipher_atbash

  • Enter substitution_cipher_atbash, then flash it into the micro:bit.

  • Open the terminal, check that local echo is checked, and make sure your keyboard is set to CAPS LOCK. 
  • Try ABCD, the result should be ZYXW.
  • Now, try ZYXW, the result should be ABCD.

How It Works – substitution_cipher_atbash

Your code has to use set result to (atbash(plaintext)) to get the ciphertext—no key required.

The atbash function has one parameter, text. The built-in key is the cryptabet, a reverse alphabet in this case. Like the other cipher functions, this one also declares an empty string named result to store the result.

Inside the loop that generates the ciphertext, it starts the same way, by finding the index of the letter in the alphabet with set index to ((alpha) find index of (letter)). What’s different is set result to (join (result) (char from(crypta) at (index))). This grabs the character with the same index in the cryptabet, and adds it to the result.

Example: Let’s say that letter is E. It’s index in the alphabet is 4. The character at crypta[4] is V, so V would be added to the result string.

Your Turn – Custom Cryptabet

Here is an alphabet that also includes digits, a space and some characters that would be useful for making a dictionary.

Alphabet: abcdefghijklmnopqrstuvwxyz 123456789:,{}’

  • Make a cryptabet by scrambling all 41 characters. 

Your Cryptabet: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

  • After making your custom cryptabet, substitute the alphabet and cryptabet into the Atbash function.
  • Rename it scrambled_alphabet.
  • Update the function call accordingly.
  • Name your project scrambled_alphabet_cipher.
  • Test to make sure that you can encrypt and decrypt this string: {‘start’ : 3, ‘after’ : ‘Liftoff! ‘}.

Printer-friendly version
ASCII and Other Simple Ciphers
Prev

DISCUSSION FORUMS | PARALLAX INC. STORE

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

© 2025 Parallax Learn • Built with GeneratePress