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

Encrypt a Single Letter

This next project will encrypt individual letters with the Caesar cipher. As written it encrypts the letter M with a key of 5.

Example project: caesar_encrypt_letter

  • Enter and flash caesar_encrypt_letter into the micro:bit.

  • Make sure your keyboard is set to CAPS LOCK.
  • Open the terminal and verify that:
    • The plaintext letter is M and its index is 12
    • The new index is 17 with the resulting ciphertext letter R.

Decrypt with Caesar Cipher

What if a project receives a Caesar encrypted character and a key? Do you need to make another project? The answer is no. To decrypt a ciphertext letter to plaintext, just use the negative of the key that encrypted it. So, if a ciphertext character was encrypted with 5, it can be decrypted with -5.

Remember how a plaintext letter M encrypted to a ciphertext letter R when the key was 5? To decrypt a ciphertext letter of R with a key of 5, just run it through the same Caesar cipher with a key of -5. The result will be the plaintext character M.

  • If you don’t already have it open, reopen caesar_encrypt_letter.
  • Set the key to -5 and the plaintext letter to “R”.
  • Flash the modified project into the micro:bit.
  • Verify that the ciphertext letter (which is really the plaintext letter) result is “M”. 

Mess around with some different letters. Do they all work perfectly? Did you run into any errors? If you used any letter above “F” you probably noticed that the new index is negative and the result doesn’t exist. That’s because we can’t search for something using negative values. It’s a pretty simple fix that we can make.

  • Start by adding an if (index < 0) before you start searching for the result.
  • Add 26 to the index if it is below 0 which should loop it properly


Printer-friendly version
Encrypt Letters with a Caesar Cipher Project
Prev
How Caesar Letter Encryption 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