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 | |
|---|---|---|
| 1plain = caesar(cipher, -shift) | Aplain = caesar(cipher, -5) | |
| 2(ord(ch) - 65 + shift) % 26 | BCalling caesar with the same positive shift shifts the letters forward again instead of back, so the message is not decrypted. It should be -shift. | |
| 3Checking that decrypt reverses encrypt: the decrypted text should equal the original message. | Cprint(caesar(caesar(msg, 3), -3) == msg) | |
| 4Decrypting a message that was encrypted with a shift of 5, using the same function. | DMoves a letter along by the shift and wraps around the alphabet, even when the shift is negative. | |
| 5plain = caesar(cipher, shift) | EDecrypts the message by calling the same Caesar function with the negative of the original shift. | |
| 6new = chr(ord(ch) - 65 + shift + 65) | FThe code is missing % 26, so letters do not wrap around the alphabet and negative shifts can give the wrong characters. It should be chr((ord(ch) - 65 + shift) % 26 + 65). |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
caesar(cipher, -shift) — Decrypts by calling the same Caesar function with the negative of the original shift. Shifting back by the same amount undoes the encryption, and % keeps the letters wrapping.plain = caesar(cipher, -shift)print(caesar(cipher, -3))cipher = caesar("HELLO", 3)
print(caesar(cipher, -3) == "HELLO")new = (ord(ch) - 65 + shift) % 26def decrypt(cipher, shift):
return caesar(cipher, -shift)