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 script will encrypt individual letters with the Caesar cipher.  As-written it encrypts the letter M with a key of 5.

Example script: caesar_encrypt_letter

  • Change project’s name from  find_letter_in_alphabet to caesar_encrypt_letter.
  • Update it to match the script below
  • Save the modified script.
  • Click the Send to micro:bit button.
# caesar_encrypt_letter
 
from microbit import *
 
sleep(1000)
 
key = 5
letter = "M"
 
alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
index = alpha.find(letter)
 
print("key =", key)
print("letter =", letter, ", index =", index)
 
index = index + key
index = index % 26
result = alpha[index]
 
print("new index =", index, ", result =", result)
 
print()
  • Check the results in the serial monitor, 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 script receives a Caesar encrypted character and a key?  Do you need to write another script?  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 script into the micro:bit.
  • Verify that the ciphertext letter (which is really the plaintext letter) result is “M”.  

 


Printer-friendly version
Encrypt Letters with a Caesar Cipher Script
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