Transposition cipher

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

Transposition cipher

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. What does a transposition cipher change about a message?
A The order of the letters
B The letters, swapped for different ones
2. A cipher turns CAT into ACT. Which type of cipher is this?
A Substitution: letters replaced with others
B Transposition: the same letters, rearranged
3. How do you write a message on a rail fence with two rails?
A Zigzag, alternating between the top rail and the bottom rail
B Write every letter on the top rail, then copy them to the bottom
4. Using two rails, how do you read off the ciphertext?
A Read down each column, one pair of letters at a time
B Read the whole top row, then the whole bottom row
5. Encrypt HELLO with a two-rail rail fence. What is the ciphertext?
A HLOEL
B ELHLO

Match the Pairs

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

Left columnRight column
1HELLO -> HLOEL ARail fence with two rails: letters 1, 3 and 5 go on the top rail, letters 2 and 4 on the bottom rail. Reading the top row then the bottom row gives HLOEL.
2Top: A T C Bottom: T A K BDEFEND -> DFNEED
3A transposition cipher keeps the same letters, so the ciphertext is just the plaintext letters in a new order. CA grid for ATTACK on two rails. Reading the rows one after the other gives the ciphertext ATCTAK.
4To read off the rows, join the top rail and then the bottom rail to make the ciphertext. DThe letters were changed by shifting them, which is a Caesar (substitution) cipher. A transposition cipher keeps the same letters and only changes their order.
5ATTACK -> DWWDFN ETop: H L O Bottom: E L -> HLOEL
6Top: H E O Bottom: L L FThe first three letters were put on the top rail. In a zigzag the letters alternate between the rails, so the top should be H L O and the bottom E L.

Definitions

transposition cipher

Fill in the Blanks

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

1.
text = "HELLO" rail1 = text[_::2] rail2 = text[1::2]
2.
text = "HELLO" rail1 = text[0::_] rail2 = text[1::2]
3.
rail1 = "HLO" rail2 = "EL" cipher = rail1 _ rail2
4.
half = (len(cipher) + 1) // 2 rail1 = cipher[:____] rail2 = cipher[half:]
5.
plain = "HELLO" cipher = "HLOEL" print(sorted(plain) __ sorted(cipher))

Spot the Error

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

Question 1
A text = "ATTACK"
B top = text[0::2]
C bottom = text[2::2]
D print(top + bottom)
Question 2
A plain = "HELLOWORLD"
B top = plain[0::2]
C bottom = plain[1::2]
D cipher = top + top
E print(cipher)
Question 3
A text = "MEETATNOON"
B rails = 2
C top = text[0::3]
D bottom = text[1::rails]
Question 4
A cipher = "ATCTAK"
B half = len(cipher) * 2
C top = cipher[:half]
D bottom = cipher[half:]
Question 5
A msg = "SENDHELP"
B row1 = msg[0:2]
C row2 = msg[1::2]
D print(row1 + row2)

Answer Key

Transposition cipher
Section A: Quick Questions
Q1
A — The order of the letters
Q2
B — Transposition: the same letters, rearranged
Q3
A — Zigzag, alternating between the top rail and the bottom rail
Q4
B — Read the whole top row, then the whole bottom row
Q5
A — HLOEL
Section B: Match the Pairs
Q1
HELLO -> HLOEL → Rail fence with two rails: letters 1, 3 and 5 go on the top rail, letters 2 and 4 on the bottom rail. Reading the top row then the bottom row gives HLOEL.
Q2
Top: A T C Bottom: T A K → A grid for ATTACK on two rails. Reading the rows one after the other gives the ciphertext ATCTAK.
Q3
A transposition cipher keeps the same letters, so the ciphertext is just the plaintext letters in a new order. → DEFEND -> DFNEED
Q4
To read off the rows, join the top rail and then the bottom rail to make the ciphertext. → Top: H L O Bottom: E L -> HLOEL
Q5
ATTACK -> DWWDFN → The letters were changed by shifting them, which is a Caesar (substitution) cipher. A transposition cipher keeps the same letters and only changes their order.
Q6
Top: H E O Bottom: L L → The first three letters were put on the top rail. In a zigzag the letters alternate between the rails, so the top should be H L O and the bottom E L.
Section C: Definitions
Q1
transposition cipher — A cipher that keeps the same letters but rearranges their order by a rule, like writing them in a zigzag on two rails and reading off the rows.
Section D: Fill in the Blanks
Q1
text = "HELLO" rail1 = text[0::2] rail2 = text[1::2]
Q2
text = "HELLO" rail1 = text[0::2] rail2 = text[1::2]
Q3
rail1 = "HLO" rail2 = "EL" cipher = rail1 + rail2
Q4
half = (len(cipher) + 1) // 2 rail1 = cipher[:half] rail2 = cipher[half:]
Q5
plain = "HELLO" cipher = "HLOEL" print(sorted(plain) == sorted(cipher))
Section E: Spot the Error
Q1
C — The bottom rail of a two-rail rail fence holds the letters at positions 1, 3, 5... so the slice must start at 1: text[1::2]. Starting at 2 skips a letter and repeats letters from the top rail.
Q2
D — The ciphertext is made by reading off the top rail and then the bottom rail. The line should be cipher = top + bottom. Using top twice loses the bottom letters.
Q3
C — A rail fence with two rails takes every 2nd letter, so the step must be 2 (rails). A step of 3 would split the message across three rails and skip letters.
Q4
B — To decrypt, the ciphertext is split in half to get the two rails back. The halfway point is len(cipher) // 2. Multiplying by 2 gives a number bigger than the message.
Q5
B — Row 1 should hold every second letter starting at the first letter, so it needs the step: msg[0::2]. msg[0:2] only gives the first two letters, so the letters are not rearranged properly.