Cyber security · GCSE · OCR J277 1.4.2, AQA 8525 3.6.3, Edexcel 1CP2 4.2.1 · about 25 min
Authenticate with a password, decrypt an encrypted command, and act on it.
[1 mark]Why does the robot authenticate before taking a command?
[1 mark]Why is the command encrypted?
[1 mark]A listener hears the Base's encrypted reply, KTWBFWI 25. What can they read without the key?
[1 mark]Authentication and encryption together protect against what?
[1 mark]If the wrong password is sent, what should the robot do?
Authenticate with the Base using the password bugbot42, decrypt its reply with a Caesar cipher (key 5), and carry out the FORWARD <cm> command to reach the green depot, without collisions. Do not send any command before the password, and do not type the distance: read it from the decrypted message. The caesar helper is provided.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
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
def ask(question, seconds=1.5):
send(question)
for tick in range(int(seconds * 10)):
wait(0.1)
for sender, text in messages():
return text
return NoneThe hint students can ask for: Send the password and wait for the reply, which is encrypted. Decrypt it with the key shifting the other way, split the command into its word and its number, and drive that far.
from bugbot import *
connect()
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
def ask(question, seconds=1.5):
send(question)
for tick in range(int(seconds * 10)):
wait(0.1)
for sender, text in messages():
return text
return None
reply = ask("bugbot42")
if reply is None:
led(255, 0, 0)
else:
command = caesar(reply, -5)
word, cm = command.split()
forward(50, distance=int(cm))
led(0, 255, 0)
Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.