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 = [random.randint(0, 25) for c in message] | ALoads Python's random module so you can call random.randint() to pick random key values | |
| 2import random | Bkey = [random.randint(0, 25) for c in message] | |
| 3A one-time pad key must be exactly as long as the message, so build it with one random value per character | CThe same random number is repeated for every character, so the key is really one value copied many times and is easy to crack. | |
| 4For stronger security, the secrets module can pick each random key value instead of random | DA one-time pad key must never be reused. Using it for a second message lets attackers compare the two messages and break the encryption. | |
| 5key = [random.randint(0, 25)] * len(message) | Ekey = [secrets.randbelow(26) for c in message] | |
| 6key = [random.randint(0, 25) for c in message] # reuse the same key for the next message | FBuilds a key list with one random number from 0 to 25 for every character 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.
key = [random.randint(0, 25) for c in message] — Builds a one-time pad key by picking one random number from 0 to 25 for each character in the message, so the key is as long as the message. Never reuse a key.import random
msg = "HELLO"
key = []key = [random.randint(0, 25) for c in msg]key = [random.randint(0, 25) for c in msg]key = []
for c in msg:
key.append(random.randint(0, 25))key = [secrets.randbelow(26) for c in msg]