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 | |
|---|---|---|
| 165 ^ 5 | AXORs the numbers 65 and 5 to give 68, the character code for D | |
| 2chr(ord(ch) ^ key) | BDecrypting with a different key (7) does not restore the original. XOR cipher needs the same key (5) for both steps. | |
| 3XOR-ing a number with the same key twice gives back the original number | Cfor c in msg: out += chr(ord(c) ^ key) | |
| 4To encrypt a whole message, XOR every character code in it with the key | D(72 ^ 9) ^ 9 | |
| 5chr("A" ^ 5) | ETurns a letter into its code, XORs it with the key, then turns the result back into a character | |
| 6plain = chr(ord(c) ^ 7) # key was 5 | FThe ^ operator needs numbers, but "A" is a string. The letter must be converted first with ord(), as in chr(ord("A") ^ 5). |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
XOR cipher — Encrypts by XOR-ing (^ in Python) each character code with a key number. XOR-ing the result with the same key again restores the original, so one key encrypts and decrypts.print(5 ^ 3)scrambled = ord("A") ^ 7key = 7
scrambled = ord("H") ^ key
back = scrambled ^ keykey = 7
letter = chr(72 ^ key)key = 9
for ch in "HI":
print(chr(ord(ch) ^ key))