3.4 Strings — Interceptors

The notebook includes Popcorn Hacks and Homework for indexing/slicing, string methods, concatenation, formatting, and CSV-style string decoding.

Popcorn Hack 1: Extract the Hidden Message

Use indexing and slicing to recover the hidden words from the intercepted signal_text.

Code Runner Challenge

Popcorn Hack 1 - Extract the hidden message using indexing and slicing

View IPYNB Source
# CODE_RUNNER: Popcorn Hack 1 - Extract the hidden message using indexing and slicing
# Slice known positions to extract each hidden word from the signal_text.
# Negative slicing gets the final word without needing the full string length.

signal_text = "xxSIGNALxxxCONFIRMEDxx77xxDELTA"

piece_one = signal_text[2:8]
print("Word 1:", piece_one)

piece_two = signal_text[11:20]
print("Word 2:", piece_two)

piece_three = signal_text[-5:]
print("Word 3:", piece_three)

print("Total length:", len(signal_text))

print("Every other character:", signal_text[::2])
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

Popcorn Hack 2: Scrub and Search a Noisy Transmission

Clean punctuation and whitespace, normalize the case, search the message, and count its words.

Code Runner Challenge

Popcorn Hack 2 - Clean and search a raw_message signal_text using string methods

View IPYNB Source
# CODE_RUNNER: Popcorn Hack 2 - Clean and search a raw_message signal_text using string methods
# Clean the message in stages: trim spaces, remove punctuation, then normalize case.
# Split the clean_message message into words so they can be counted.

raw_message = "   ...AGENT>>>Falcon---reports: the PACKAGE has ARRIVED!!!   "

trimmed_message = raw_message.strip()
print("Trimmed:", repr(trimmed_message))

clean_message = trimmed_message.replace(">", "").replace("-", "").replace("!", "")
print("Cleaned:", clean_message)

lower_message = clean_message.lower()
print("Lowered:", lower_message)

has_arrived = "arrived" in lower_message
print("Contains 'arrived':", has_arrived)

words = clean_message.split()
print("Word count:", len(words))
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

Popcorn Hack 3: Build a Decoded Report

Rebuild the decoded information using concatenation, type conversion, f-strings, and join().

Code Runner Challenge

Popcorn Hack 3 - Build a decoded report using concatenation and formatting

View IPYNB Source
# CODE_RUNNER: Popcorn Hack 3 - Build a decoded report using concatenation and formatting
# Store report pieces in variables and combine them into readable output.
# join() connects fragments and an f-string builds the final formatted report.

agent_name = "Falcon"
target_word = "MIDNIGHT"
confidence = 87
fragments = ["ALPHA", "SEVEN", "DELTA"]

headline = "Agent " + agent_name + " intercepted: " + target_word
print(headline)

confidence_line = "Confidence: " + str(confidence) + "%"
print(confidence_line)

confidence_line_fstring = f"Confidence: {confidence}%"
print(confidence_line_fstring)

joined_fragments = "-".join(fragments)
print("Joined fragments:", joined_fragments)

final_report = f"REPORT: {headline} | {confidence_line} | Fragments: {joined_fragments}"
print(final_report)
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

Homework Hack: Crack the Final Transmission

Decode the CSV-style signal_text using splitting, indexing, slicing, replacement, searching, and formatted Markdown/JSON output.

Code Runner Challenge

Homework - Crack the Final Transmission using slicing, methods, and formatting

View IPYNB Source
# CODE_RUNNER: Homework - Crack the Final Transmission using slicing, methods, and formatting
# Strip extra spaces and split the CSV-style signal_text into separate fields.
# Decode and search the message, then format the result as Markdown and JSON-style text.

raw_signal_text = "  2026-09-15,GHOST,THE-EAGLE-LANDS-AT-DAWN,87  "

fields = raw_signal_text.strip().split(",")
print("Segments:", fields)

date = fields[0]
agent = fields[1]
coded_message = fields[2]
confidence_text = fields[3]
print("Date:", date, "| Agent:", agent, "| Message code:", coded_message, "| Confidence:", confidence_text)

year_check = date[:4]
print("Year check:", year_check)

message = coded_message.replace("-", " ")

found_dawn = "dawn" in message.lower()
print("Found 'dawn':", found_dawn)

markdown_row = f"| {date} | {agent} | {message} | {confidence_text}% |"
print("Markdown row:", markdown_row)

json_line = ('{"date": "' + date
    + '", "agent": "' + agent
    + '", "message": "' + message
    + '", "confidence": ' + confidence_text
    + ', "contains_dawn": ' + str(found_dawn).lower()
    + '}')
print("JSON line:", json_line)
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...