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[i % len(key)] | Aif ch.isalpha(): k = key[j % len(key)] j += 1 | |
| 2shift = ord(k) - 65 | BTurns an uppercase keyword letter into a shift number from 0 to 25 (A is 0, B is 1, and so on). | |
| 3Only letters use up the keyword, so a counter j goes up only when the character is a letter and spaces are skipped. | CPicks the keyword letter for position i and wraps back to the start of the keyword when i passes its length. | |
| 4To decrypt a Vigenere message, subtract the keyword shift instead of adding it, and wrap with % 26. | Dj goes up for spaces and punctuation as well as letters, so the keyword gets out of step with the letters being encrypted. | |
| 5k = key[i] | EThere is no % len(key), so the index runs past the end of the keyword on a long message and causes an IndexError. | |
| 6k = key[j % len(key)] j += 1 # runs for every character | Fchr((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.
key[i % len(key)] — Picks the keyword letter for position i and wraps back to the start with %, so each message letter gets its own shift. This is how a Vigenere cipher loop cycles the keyword.k = key[i % len(key)]k = key[i % len(key)]if ch.isalpha():
k = key[n % len(key)]
n = n + 1shift = ord(key[i % len(key)]) - 65
new = (ord(ch) - 65 - shift) % 26shift = ord(key[i % len(key)]) - 65
new = (ord(ch) - 65 + shift) % 26 + 65