One-time pad

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

One-time pad

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which key length makes a one-time pad work?
A A key as long as the message
B A short key that repeats over the message
2. How should the key for a one-time pad be generated?
A From a memorable phrase such as a pet's name
B Truly randomly
3. Alex encrypts two different messages with the same pad page. Is this safe?
A No, a pad key must never be reused
B Yes, the key is random so it can be used again
4. Why is a one-time pad described as unbreakable in theory?
A A random, single-use key leaves no pattern to analyse
B Computers are not yet fast enough to try every key
5. Which is the biggest challenge of sharing a one-time pad?
A The pad can be sent openly because it is random
B Both parties need the same pad, delivered securely

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1key = random_bytes(len(message)) AThe key is shorter than the message and is not random, so it would have to repeat and the pad is no longer unbreakable
2pad_used = True BMarks the pad as used so it is never used to encrypt a second message
3A one-time pad key must be at least as long as the message, so a 500-character message needs a 500-character key CGenerates a truly random key exactly as long as the message, as a one-time pad needs
4A one-time pad is impractical for large data because the pad must be as big as the data and shared securely first DThe same pad is reused for two messages, so an attacker can compare the ciphertexts and the security is lost
5key = "SECRET" message = "MEET AT NOON" Epad_size = len(video_file)
6encrypt(msg1, pad) encrypt(msg2, pad) Fif len(key) < len(message):

Definitions

one-time pad

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
if len(key) __ len(message): print("Pad is long enough")
2.
cipherNum = (letterNum + padNum) _ 26
3.
if pad __ usedPads: print("Never reuse a pad")
4.
key = [random._______(0, 25) for c in msg]
5.
padSize = ___(bigFile) print(padSize, "bytes to share securely")

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A import random
B msg = [7, 4, 11, 11, 14]
C key = []
D for n in range(3):
E key.append(random.randint(0,25))
Question 2
A key = make_key(len(msg) - 2)
B cipher = []
C for i in range(len(msg)):
D c = (msg[i] + key[i]) % 26
E cipher.append(c)
Question 3
A msg = input('Message: ')
B pad = last_pad
C cipher = encrypt(msg, pad)
D send(cipher)
E destroy(pad)
Question 4
A pad = random_pad(len(msg))
B share(pad, 'public_forum')
C cipher = encrypt(msg, pad)
D send(cipher, 'internet')
Question 5
A for i in range(len(c)):
B n = (c[i] + pad[i]) % 26
C plain.append(n)

Answer Key

One-time pad
Section A: Quick Questions
Q1
A — A key as long as the message
Q2
B — Truly randomly
Q3
A — No, a pad key must never be reused
Q4
A — A random, single-use key leaves no pattern to analyse
Q5
B — Both parties need the same pad, delivered securely
Section B: Match the Pairs
Q1
key = random_bytes(len(message)) → Generates a truly random key exactly as long as the message, as a one-time pad needs
Q2
pad_used = True → Marks the pad as used so it is never used to encrypt a second message
Q3
A one-time pad key must be at least as long as the message, so a 500-character message needs a 500-character key → if len(key) < len(message):
Q4
A one-time pad is impractical for large data because the pad must be as big as the data and shared securely first → pad_size = len(video_file)
Q5
key = "SECRET" message = "MEET AT NOON" → The key is shorter than the message and is not random, so it would have to repeat and the pad is no longer unbreakable
Q6
encrypt(msg1, pad) encrypt(msg2, pad) → The same pad is reused for two messages, so an attacker can compare the ciphertexts and the security is lost
Section C: Definitions
Q1
one-time pad — Encryption using a truly random key as long as the message, used only once. Never reused, it is unbreakable in theory, but the pad must be shared securely.
Section D: Fill in the Blanks
Q1
if len(key) == len(message): print("Pad is long enough")
Q2
cipherNum = (letterNum + padNum) % 26
Q3
if pad in usedPads: print("Never reuse a pad")
Q4
key = [random.randint(0, 25) for c in msg]
Q5
padSize = len(bigFile) print(padSize, "bytes to share securely")
Section E: Spot the Error
Q1
D — The key must be as long as the message. Looping over only 3 values gives a key shorter than the 5-number message. It should be for n in msg: so there is one random key value per message value.
Q2
A — A one-time pad key must be exactly as long as the message. Subtracting 2 leaves the last two characters with no key value. It should be key = make_key(len(msg)).
Q3
B — A one-time pad key must never be reused. Using last_pad recycles an old key, which breaks the security. It should generate a fresh random pad: pad = random_pad(len(msg)).
Q4
B — The pad must be shared securely, such as by handing it over in person. Posting it on a public forum lets an interceptor read the message. It should be share(pad, 'in_person').
Q5
B — Encryption adds the pad value, so decryption must subtract the same pad value. Adding again gives the wrong letters. It should be n = (c[i] - pad[i]) % 26.