Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1key = ''.join(random.choice(string.ascii_uppercase) for _ in message) | Akey = generate_key(len(message)) | |
| 2if len(key) != len(message): | BThe key is shorter than the message, so key[i] causes an IndexError and the key would have to repeat. A one-time pad key must be as long as the message. | |
| 3Each message letter is shifted by the matching key letter, so the key never repeats | CChecks that the key is the same length as the message | |
| 4A key that has been used once must be thrown away and never reused | DThe same key is used for two messages. Reusing a one-time pad key makes it breakable. | |
| 5key = 'KEY' for i in range(len(message)): shift = ord(key[i]) - 65 | Eshift = ord(key[i]) - 65 | |
| 6key = 'XMCKL' secret1 = encrypt('HELLO', key) secret2 = encrypt('WORLD', key) | FBuilds a random key with one random letter for every letter in the message |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
one-time pad — A cipher that encrypts each letter with a random key letter. The key is as long as the message and is used once only, so it is unbreakable if used correctly.key = ""
for i in range(len(message)):
key += random.choice(letters)for i in range(len(message)):
key += random.choice(letters)shift = ord(kch) - 65
code = (ord(ch) - 65 + shift) % 26if key in used:
print("Key reused - not secure!")if len(key) < len(message):
print("Key too short!")