VR - Mission 15: Cyber Storm

Mission 15 Lesson Plan

Storm

Students help protect an email server by using file operations to read, search, and filter suspicious emails.

⏰ 2-3 hours 🎯 Grades 9-12+ πŸ’» CodeSpace πŸ€– Virtual CodeBot 🐍 Python
View Lesson Outline
πŸ“‹

Overview

In Cyber Storm, students step into the role of a cybersecurity analyst protecting an email server from malicious messages. Working entirely with file operations and string methods, they open and read email files, build a dictionary from each email's heading and body, search that body for suspicious keywords, and remove or flag the emails that pose a risk. By the end of the mission, students have written a working blocklist program that reads a file, checks its contents, and removes senders who don't belong.

🎯 Mission Goal: Students help protect an email server by using file operations.

🎯

Learning Targets

  • I can open and read from a file.
  • I can check for special characters.
  • I can create a dictionary from an email file.
  • I can search for a specific word and replace it with a different word.
  • I can create a list of blocked users and remove their emails.
πŸ’‘

Key Concepts

  • File operations include a variety of ways to open, read, write, and append to a file.
  • The with statement is a for loop for files that automatically closes the file.
  • Use in or not in to search through a string.
  • A string can be manipulated with methods such as replace.
  • A new file can be created and data added to the file using append.
βœ…

Assessment Opportunities

  • Quiz after Objective 4
  • Quiz after Objective 8
  • Code Tracing Chart as a debugging tool
  • Submit program code, or give students printed code and have them explain each line: Objective 3, Objective 5, Objective 7, Objective 8
  • Give extra practice with file operations
  • Give extra practice with string operations
  • Submit final blocklist program
  • Mission 15 Review Kahoot!
β˜‘οΈ

Success Criteria

  • Open and read data from a file.
  • Create a dictionary of an email's heading and body.
  • Search the body of an email for suspicious keywords.
  • Create a blocklist file and use it to remove suspicious emails.
🧰

Classroom Materials

  • β–ΈComputer or Chromebook with internet access
🌍

Real-World Applications

πŸ›‘οΈThis mission uses files and file operations. Programmers write code all the time that searches files and creates new files.
πŸ”’Other than cybersecurity, there are many other applications for searching files and creating new files. Protecting data is extremely important in today's world, and searching for suspicious emails is one way to avoid malware.
πŸ’»Discuss other ways to protect your computer and your data.
πŸš€

Extensions & Cross-Curricular

ExtensionUse CodeBot with the email protection program. Add LEDs or sounds to indicate a potential malicious email.
ExtensionUse a button press to start the email protection program.
ExtensionUse the console to get input from the user, like a filename or malicious word to search for.
ExtensionAdd a list of malicious words to search for instead of a single word.
Lang ArtsHave students describe in detail how one of their functions works.
MathThe clean_line function can create a substring of a string using each letter's position (or index). Create an algorithm or equation that automates this process without needing "magic numbers."
ScienceThe mission checks for a potential virus that could infect a computer. Discuss viruses that infect people, how they are spread, and how they can be mitigated.
πŸ”€

Vocabulary

β–Ύ
'with' statement:A type of for loop for files that automatically closes the file.
Escape sequence:A way to insert a special character using \. Common escape sequences are: '\n' for new line, '\r' for carriage return, '\t' for tab.
strip() function:A function that removes characters from the beginning and end of a string.
Whitespace:Whitespaces include a space, a tab, a carriage return, and a new line (escape sequences).
Concatenation:Appending (or joining) a string.
startswith(prefix):The function returns True if the string starts with the given prefix.
'in' and 'not in':Used in a for loop to check if a value exists (or doesn't exist) in a sequence.
replace() function:Takes two arguments and replaces the first argument with the second in a string.
Blocklist:A list of disallowed senders.
🐍

New Python Code

β–Ύ
with open(email_file, 'r') as f: file_contents = f.readlines() print(file_contents) Open a file using a 'with' loop.
line.strip() Strips whitespace from a line.
email = email + line.strip() Concatenate (or join) a string.
with open(email_file, 'r') as f: email = {} for line in f: if line.startswith('Date: '): email['date']=clean_line[6:] elif line.startswith('From: '): email['from']=clean_line[6:] ... Create a dictionary with the email heading.
elif line.strip() == '': email['body'] = f.read() Find the body of the email (used at the end of the heading if/elif statement).
if 'virus' in email['body']: Look for a word in a string.
email['body'].replace('virus', 'REMOVED') Replace a word in a string.
import os Import a library to use os functions and methods.
if not os.path.exists('blocklist.csv'): print("Creating blocklist!") Check to see if a file exists.
f.write(bl_entry) Write a new item to a file.
if sender in blocklist: os.remove(filename) Remove a file.
πŸ“

Standards

β–Ύ

CSTA Standards - Grades 9-10

3A-CS-03 3A-NI-07 3A-NI-08 3A-DA-10 3A-AP-13 3A-AP-14 3A-AP-15 3A-AP-16 3A-AP-17 3A-AP-18 3A-AP-21 3A-AP-26

CSTA Standards - Grades 11-12

3B-NI-04 3B-DA-05 3B-AP-10 3B-AP-12 3B-AP-14 3B-AP-15 3B-AP-16 3B-AP-18 3B-AP-21 3B-AP-22 3B-AP-23

Certiport IT Specialist: Python Standards

1.1 1.2 1.3 1.4 2.1 2.2 3.1 4.1 4.2 6.1

PCEP: Certified Entry-Level Python Programmer

1.1 1.2 1.3 1.4 1.5 2.1 2.2 3.1 3.3 3.4 4.1 4.2
πŸ“
Preparing for the Lesson
  • This mission does not use the CodeBot - it uses the console for displaying information, so no hardware setup is needed.
  • There are several CSTA standards specific to networks, privacy, and security in this mission - before or after Cyber Storm is a good time for additional lessons and discussions on these topics.
  • Plan for students to do a "save as" at the beginning of each objective, so they can refer back to methods taught earlier.

πŸ§‘β€πŸ«
Teacher Notes
  • The name of the file used in the program changes frequently from one objective to another - make sure students are using the correct filename each time.
  • This mission uses many file operations. It's a good time to do some extra practice and review of file and string methods.
πŸ—ΊοΈ

Lesson Outline

πŸ—£οΈWarm-up / Hook

Ask students if they've ever gotten a suspicious email, or heard of phishing or malware spreading through email. Introduce the mission: they'll write a program that reads an email server's messages, checks them for suspicious content, and removes emails from blocked senders - all using file operations.

1️⃣Objectives 1-2: Opening and Reading Files
  • Open a file with a with statement, read its contents, and use strip() to clean up whitespace and escape sequences from each line.
  • Reference Mission 15 Obj 2 as needed.
Teaching tip: Review escape sequences ('\n', '\r', '\t') and whitespace before this objective - students will run into them right away when printing raw file contents.
2️⃣Objectives 3-4: Building the Email Dictionary
  • Use startswith() to identify each heading line and build a dictionary of the email's date, sender, and other header fields.
  • Submit program code for Objective 3, or have students explain each line.
  • Reference Mission 15 Obj 4 as needed. Administer the Quiz after Objective 4.
Teaching tip: Use the Code Tracing Chart here as a debugging tool - it helps students see exactly what's being added to the dictionary at each step.
3️⃣Objective 5: Finding and Searching the Email Body
  • Find the blank line that separates the heading from the body, read the rest of the file into email['body'], and use in to search it for a suspicious keyword.
  • Submit program code for Objective 5, or have students explain each line.
  • Reference Mission 15 Obj 5 as needed.
Teaching tip: Give extra practice with string operations here - searching text for keywords is the core skill the rest of the mission builds on.
4️⃣Objectives 6-7: Replacing Suspicious Words
  • Use the replace() method to swap a flagged word out of the email body.
  • Submit program code for Objective 7, or have students explain each line.
  • Reference Mission 15 Obj 7 as needed.
5️⃣Objective 8: Building the Blocklist
  • Import os, check whether a blocklist file already exists, write new blocked senders to it with f.write(), and remove emails from any sender on the list with os.remove().
  • Submit program code for Objective 8, or have students explain each line. Administer the Quiz after Objective 8.
  • Have students give extra practice with file operations here if time allows, then submit their final blocklist program.
Teaching tip: Give extra practice with file operations before wrapping up - this objective pulls together everything from opening files to removing them.
πŸŽ‰Wrap-up / Review

Close with the Level-1 Mission 15 Review Kahoot! to reinforce file operations, string searching, and the blocklist workflow before moving on to the Unit 6 Remix & Assessment.