Cyber security · GCSE · OCR J277 1.4.2, AQA 8525 3.6.3, Edexcel 1CP2 5.3.2 · about 20 min
Plaintext, keys and ciphertext, the Caesar cipher, symmetric and asymmetric, and a secret over the radio.
[1 mark]What is encryption?
[1 mark]Encrypt HELLO with a Caesar cipher, key 1.
[1 mark]Why is the Caesar cipher easy to break?
[1 mark]In asymmetric encryption, what can be shared openly?
[1 mark]What does the padlock and https in a browser mean?
[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))CDE
A->C, B->D, C->E.
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.
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.