← Teacher guide

Scrambling is not a secret

Students send a reversed message, see that anyone who knows the method can undo it, and meet the idea of a public method with a secret key.

Secret messages · Messages in the air · about 40 minutes · Open the student lesson

Classroom resources

Load these into Waypoints Prepare: choose Load URL and paste the copied address, or download the file and import it. In Prepare, the worksheet's Teacher edition shows the answers; the student copy hides them.

Students will be able to

Timing

Predict and Run 7 min · Investigate 10 min · Modify 6 min · Make 15 min

Before class

The idea: a cipher is a method for scrambling a message. If the method is the only secret, everything is lost the moment someone learns it. Real ciphers have a public method and a secret key; Caesar's cipher, next, is the smallest example.

Vocabulary: plain text (before), cipher text (after), method (steps), key (the secret value). Use them every time from now on.

Code: this lesson teaches the code every later cipher is built from. Foundations functions were named jobs with nothing in or out; reverse(text) takes a parameter and returns a text. The for index loop visits each place 0 to length − 1, and text.charAt(i) is the letter at place i (counted from 0, like a list). The Investigate trace task (result after i = 0 and 1) checks students can follow it; spend time here, because Caesar, Checksum and the CTF reuse the same shape.

Running the lesson

  1. Predict: students expect HELLO. Ask: where in the program is the reversing undone?
  2. Make: let pairs swap and guess. The point is that a guess at the method is cheap.

The hard part (on purpose)

A method everyone knows hides nothing. Ask what a listener who knows the method would need to read the message.

When students get stuck

What you will seeA question to askThe fix
The receiver shows OLLEH.Where does the receiver undo the reversing?Show reverse(received string) instead of received string.
The text comes out shorter or longer than expected in unscramble.Which letters does unscramble keep?Loop i up to half the length, and join the letter at place i × 2.

Answers to the checks

  1. Predict: A is pressed. What does the other micro:bit show?
    OLLEH. The receiver shows exactly what the radio carried, and the radio carried the reversed text. The receiver never undoes it.
  2. Inside reverse: In reverse("HELLO"), what is result after the loop has run for i = 0 and then i = 1?
    EH
    At i = 0 the letter at place 0, H, is joined in front of the empty result: H. At i = 1, E is joined in front: EH. Each new letter goes on the front, so the order flips.
  3. Undoing it: Sam knows the sender reverses every message. A message arrives: OLLEH. What does Sam do to read it?
    Reverse it again
    Reversing twice gets back the original. Once the method is known, the scrambling is no protection.
  4. The parts of a code: Match each part of a code with its job.
    The method → C. the steps for scrambling and unscrambling; can be public; The key → B. a secret value the method needs; only the two people know it; The plain text → A. the message before it is scrambled; The cipher text → D. the scrambled message that travels
  5. What to protect: Which is the better rule for a code?
    Assume the method is known, and keep only the key secret
    Methods leak: they get copied, written down and guessed. A key can be changed in a moment, so the key is what to protect.

Solutions

One possible solution for each task. Other correct programs are fine.

Modify

The program as blocks
Show as code
function reverse(text: string): string {
    let result = ""
    for (let i = 0; i < text.length; i++) {
        result = text.charAt(i) + result
    }
    return result
}
radio.setGroup(5)
input.onButtonPressed(Button.A, function () {
    radio.sendString(reverse("HELLO"))
})
radio.onReceivedString(function (receivedString) {
    basic.showString(reverse(receivedString))
})

Make

The program as blocks
Show as code
function scramble(text: string): string {
    let result = ""
    for (let i = 0; i < text.length; i++) {
        result = result + text.charAt(i) + "X"
    }
    return result
}
function unscramble(text: string): string {
    let result = ""
    for (let i = 0; i < text.length / 2; i++) {
        result = result + text.charAt(i * 2)
    }
    return result
}
radio.setGroup(5)
input.onButtonPressed(Button.A, function () {
    radio.sendString(scramble("MEET AT 3"))
})
radio.onReceivedString(function (receivedString) {
    basic.showString(unscramble(receivedString))
})

Stretch and support

Stretch: Make the scrambler swap each pair of letters (HELLO → EHLLO).

Support: Give scramble complete and ask only for unscramble.

Exit ticket

Why is a message that is scrambled with a method everyone knows not private?

Anyone who knows the method can undo it. A code needs a secret key that is separate from the method.

What each step is for

Where it leads

Next: a code with a key, the Caesar cipher.