The worksheetDownload the PDF
Answers

F11.6 Encryption

Cyber security · GCSE · OCR J277 1.4.2, AQA 8525 3.6.3, Edexcel 1CP2 5.3.2 · about 20 min

BugBotLab

What this lesson is about

Plaintext, keys and ciphertext, the Caesar cipher, symmetric and asymmetric, and a secret over the radio.

Questions 6 marks in all

  1. [1 mark]What is encryption?

    1. AScrambling data so only someone with the key can read it
    2. BMaking data smaller
    3. CDeleting data safely
    4. DCopying data to another place
    Answer: A. Ciphertext is useless without the key.
  2. [1 mark]Encrypt HELLO with a Caesar cipher, key 1.

    Answer: IFMMP. Each letter moves one along.
  3. [1 mark]Why is the Caesar cipher easy to break?

    1. AThere are only 25 possible keys to try
    2. BIt uses no key
    3. CIt cannot be decrypted
    4. DIt only works on numbers
    Answer: A. A computer tries all 25 in an instant.
  4. [1 mark]In asymmetric encryption, what can be shared openly?

    1. AThe public key
    2. BThe private key
    3. CThe plaintext
    4. DBoth keys
    Answer: A. The private key stays secret; the public key can be shared.
  5. [1 mark]What does the padlock and https in a browser mean?

    1. AThe connection is encrypted
    2. BThe site is free
    3. CThe site is fast
    4. DThe site has no adverts
    Answer: A. Data sent is encrypted, so interception reveals only ciphertext.
  6. [1 mark]What does this program print?

    def caesar(t, k):
        return ''.join(chr((ord(c) - 65 + k) % 26 + 65) for c in t)
    print(caesar('ABC', 2))
    Answer:
    CDE

    A->C, B->D, C->E.

The task: send a secret

Write caesar(text, key) that shifts letters by the key and leaves anything else unchanged. Using a key of 7, encrypt message, print sending: <ciphertext>, and send the ciphertext by radio. The Ally replies with its own encrypted message; decrypt each reply and print reply means: <plaintext>. You should read the Ally saying ALL CLEAR.

# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()

message = "MEET AT BASE"

The hint students can ask for: Encrypt the message with the shared key, report what you are sending, and send that rather than the plain words. Decrypt each reply by shifting the other way.

A solution

from bugbot import *
connect()
message = "MEET AT BASE"

def caesar(text, key):
    out = ""
    for ch in text:
        if ch.isalpha():
            base = ord("A")
            out = out + chr((ord(ch.upper()) - base + key) % 26 + base)
        else:
            out = out + ch
    return out

secret = caesar(message, 7)
print("sending:", secret)
send(secret)
for tick in range(10):
    wait(0.1)
    for sender, text in messages():
        print("reply means:", caesar(text, -7))

Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.