Data representation · A level · OCR H446 1.3.1, AQA 7517 4.5.6.9 · about 40 min
Run length and dictionary coding, the Caesar and Vernam ciphers, symmetric and asymmetric encryption, and hashing.
[1 mark]A program's source code is compressed to send it by email. Which kind of compression must be used, and why?
[1 mark]What does this program print?
row = "AAAABBBCCD"
out = ""
i = 0
while i < len(row):
j = i
while j < len(row) and row[j] == row[i]:
j = j + 1
out = out + str(j - i) + row[i]
i = j
print(out)[1 mark]Which conditions must a Vernam cipher key meet for perfect security?
Tick every answer that is true.
[1 mark]What does it mean for a cipher to be computationally secure?
[1 mark]Why are passwords stored as hashes rather than encrypted?
[1 mark]Alice wants to send Bob a message using asymmetric encryption. Which key does she encrypt it with?
route is a string of words separated by single spaces: FWD <cm> and LEFT <degrees> commands.
1. Write encode(text). The parameter text is a string of words separated by single spaces. It returns a pair: a list of the different words in the order they first appear (the dictionary), and a string of each word's index in that list, separated by single spaces.
2. Write decode(dictionary, encoded), which takes those two values and returns the original string.
3. Print dictionary: <the words separated by spaces>, then encoded: <the encoded string>, then original: <n> characters, encoded: <m> characters using len of route and of the encoded string, then decoded matches: <True or False> comparing the decoded string with route.
4. Drive the decoded route: FWD n is forward(50, distance=n) and LEFT n is turn_left(angle=n), where n is the number after the word.
Build the encoded string with your function; do not type it in.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
route = "FWD 20 LEFT 90 FWD 20 LEFT 90 FWD 20 LEFT 90 FWD 20 LEFT 90"
def encode(text):
dictionary = []
codes = []
return dictionary, " ".join(codes)
def decode(dictionary, encoded):
return ""Plan your program here, then type it in and press Run.
KEY, XOR the two ciphertexts, and compare with the XOR of the two plaintexts. What does this tell an attacker?toy_hash as a hash table of 16 slots for ten commands. How will you store two commands that collide?