Substitution cipher

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

Substitution cipher

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. A substitution cipher uses a scrambled alphabet as its key. Which description fits it best?
A Each letter is swapped for a different letter using a key table
B Every letter is moved along by the same number of places
2. Here is a key table: A→Q, B→W, C→E. How is the word CAB encrypted?
A QWE
B EQW
3. To decrypt a message made with a substitution cipher, what do you do with the key table?
A Use the table the same way again to encrypt the ciphertext a second time
B Use the table in reverse, finding each cipher letter and reading the plain letter
4. Using the table A→Q, B→W, C→E, what does the ciphertext WQE decrypt to?
A BAC
B CAB
5. Which key would a substitution cipher use?
A A scrambled alphabet such as QWERTYUIOPASDFGHJKLZXCVBNM
B A single number such as 3

Match the Pairs

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

Left columnRight column
1key = QWERTYUIOPASDFGHJKLZXCVBNM AThe table was used forwards. M is what Z encrypts to, not what Z decrypts to.
2DOG -> RGU BThe key repeats N and leaves out M. Two plain letters would share one cipher letter, so decrypting would be ambiguous.
3To decrypt, use the key table in reverse: find the cipher letter, then read off the plain letter it replaced CEncrypting DOG with the key table: D becomes R, O becomes G and G becomes U
4Each letter swaps for a different letter with no fixed shift, so it is not a Caesar shift DA -> Q, B -> W, C -> E
5key = QWERTYUIOPASDFGHJKLZXCVBNN EA scrambled alphabet key: A becomes Q, B becomes W, C becomes E, and so on for all 26 letters
6Decrypt Z: Z -> M FQ -> A, E -> C, Z -> T

Definitions

substitution cipher

Fill in the Blanks

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

1.
alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ___ = "QWERTYUIOPASDFGHJKLZXCVBNM"
2.
alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" key = "QWERTYUIOPASDFGHJKLZXCVBNM" cipher = key[alphabet._____("A")]
3.
alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" key = "QWERTYUIOPASDFGHJKLZXCVBNM" plain = ________[key.index("Q")]
4.
coded = "" for letter __ message: coded += key[alphabet.index(letter)]
5.
table = {"A": "Q", "B": "W", "C": "E"} reverse = {v: k for k, v in table._____()} print(reverse["W"])

Spot the Error

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

Question 1
A plain = "ABCDE"
B key = "XQMZP"
C pos = plain.index("C")
D print(plain[pos])
Question 2
A plain = "ABCDE"
B key = "BCDEA"
C out = ""
D for ch in "BAD":
E out += key[plain.index(ch)]
Question 3
A key = {"A": "Q", "B": "Q"}
B out = key["A"] + key["B"]
C print(out)
Question 4
A enc = {"A": "Q", "B": "W"}
B dec = {"Q": "A", "W": "B"}
C print(enc["Q"], enc["W"])
Question 5
A FOR each word in message
B find it in the plain row
C replace with the key letter
D END FOR

Answer Key

Substitution cipher
Section A: Quick Questions
Q1
A — Each letter is swapped for a different letter using a key table
Q2
B — EQW
Q3
B — Use the table in reverse, finding each cipher letter and reading the plain letter
Q4
A — BAC
Q5
A — A scrambled alphabet such as QWERTYUIOPASDFGHJKLZXCVBNM
Section B: Match the Pairs
Q1
key = QWERTYUIOPASDFGHJKLZXCVBNM → A scrambled alphabet key: A becomes Q, B becomes W, C becomes E, and so on for all 26 letters
Q2
DOG -> RGU → Encrypting DOG with the key table: D becomes R, O becomes G and G becomes U
Q3
To decrypt, use the key table in reverse: find the cipher letter, then read off the plain letter it replaced → Q -> A, E -> C, Z -> T
Q4
Each letter swaps for a different letter with no fixed shift, so it is not a Caesar shift → A -> Q, B -> W, C -> E
Q5
key = QWERTYUIOPASDFGHJKLZXCVBNN → The key repeats N and leaves out M. Two plain letters would share one cipher letter, so decrypting would be ambiguous.
Q6
Decrypt Z: Z -> M → The table was used forwards. M is what Z encrypts to, not what Z decrypts to.
Section C: Definitions
Q1
substitution cipher — A cipher that swaps each letter for a different letter or symbol using a key table, like a scrambled alphabet. It is not a simple shift, and the table is used in reverse to decrypt.
Section D: Fill in the Blanks
Q1
alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" key = "QWERTYUIOPASDFGHJKLZXCVBNM"
Q2
alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" key = "QWERTYUIOPASDFGHJKLZXCVBNM" cipher = key[alphabet.index("A")]
Q3
alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" key = "QWERTYUIOPASDFGHJKLZXCVBNM" plain = alphabet[key.index("Q")]
Q4
coded = "" for letter in message: coded += key[alphabet.index(letter)]
Q5
table = {"A": "Q", "B": "W", "C": "E"} reverse = {v: k for k, v in table.items()} print(reverse["W"])
Section E: Spot the Error
Q1
D — This prints the plain letter C again, so nothing is substituted. To encrypt, take the letter at the same position in the key row: print(key[pos]).
Q2
B — BCDEA is just the alphabet shifted by one, which is a Caesar shift. A substitution cipher needs a scrambled key such as "XQMZP".
Q3
A — Two plain letters now share the cipher letter Q. The receiver could not tell which one it came from when decrypting. Each letter needs its own cipher letter, e.g. "B": "W".
Q4
C — enc maps plain letters to cipher letters, so looking up Q and W in it fails. To decrypt, use the reversed table: print(dec["Q"], dec["W"]).
Q5
A — A substitution cipher swaps one letter at a time using the key table, not whole words. The loop should be FOR each letter in message.