Encode and decode

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

Encode and decode

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which word means turning information into a code?
A Decode
B Encode
2. Which word means turning a code back into the information?
A Encode
B Decode
3. Mia swaps each letter in her message for a number, so A becomes 1 and B becomes 2. What is she doing?
A Encoding the message
B Decoding the message
4. Leo gets the secret message 8 9. He uses the key A=1, B=2 and so on to read it as HI. What is he doing?
A Decoding the message
B Encoding the message
5. Which statement is true about encode and decode?
A They are opposites
B They mean the same thing

Match the Pairs

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

Left columnRight column
1encode("CAT") gives 3 1 20 ADecoding needs the key. Without it you cannot tell which number stands for which letter.
2decode("3 1 20") gives CAT Bencode(picture) gives 0 1 1 0
3Encoding a black-and-white picture: black pixels become 1 and white pixels become 0 CThis turns the word into a code, so it is encoding. Decoding should turn the code back into the word.
4Decoding with a key: the key says 1 means black and 0 means white, so the digits become a picture again DUses the key to turn the number codes back into the word
5decode("CAT") gives 3 1 20 ETurns the word CAT into number codes, so the information is now in code
6decode("3 1 20") without a key Fdecode("0 1 1 0", key) gives picture

Definitions

encode / decode

Fill in the Blanks

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

1.
message ← "CAB" code ← ______(message, key)
2.
code ← "3 1 2" message ← ______(code, key)
3.
code ← "3 1 2" message ← decode(code, ___)
4.
picture ← [0, 1, 1, 0] code ← encode(_______, key)
5.
code ← encode(message, key) original ← ______(code, key) output original

Spot the Error

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

Question 1
A key ← A=1, B=2, C=3
B message ← "CAB"
C code ← encode(message, key)
D answer ← encode(code, key)
E show answer
Question 2
A key ← A=1, B=2, C=3
B message ← BAC
C code ← encode(message, key)
D show code
Question 3
A row ← black, white, black
B key ← black=1, white=0
C code ← decode(row, key)
D show code
Question 4
A code ← 1, 0, 1
B key ← 1=black, 0=white
C row ← decode(code)
D show row
Question 5
A key ← A=1, B=1, C=3
B word ← "ABC"
C code ← encode(word, key)
D show code

Answer Key

Encode and decode
Section A: Quick Questions
Q1
B — Encode
Q2
B — Decode
Q3
A — Encoding the message
Q4
A — Decoding the message
Q5
A — They are opposites
Section B: Match the Pairs
Q1
encode("CAT") gives 3 1 20 → Turns the word CAT into number codes, so the information is now in code
Q2
decode("3 1 20") gives CAT → Uses the key to turn the number codes back into the word
Q3
Encoding a black-and-white picture: black pixels become 1 and white pixels become 0 → encode(picture) gives 0 1 1 0
Q4
Decoding with a key: the key says 1 means black and 0 means white, so the digits become a picture again → decode("0 1 1 0", key) gives picture
Q5
decode("CAT") gives 3 1 20 → This turns the word into a code, so it is encoding. Decoding should turn the code back into the word.
Q6
decode("3 1 20") without a key → Decoding needs the key. Without it you cannot tell which number stands for which letter.
Section C: Definitions
Q1
encode / decode — To encode is to turn information into a code. To decode is to turn the code back into the information, using a key. They are opposites.
Section D: Fill in the Blanks
Q1
message ← "CAB" code ← encode(message, key)
Q2
code ← "3 1 2" message ← decode(code, key)
Q3
code ← "3 1 2" message ← decode(code, key)
Q4
picture ← [0, 1, 1, 0] code ← encode(picture, key)
Q5
code ← encode(message, key) original ← decode(code, key) output original
Section E: Spot the Error
Q1
D — To get the message back from the code you must decode, not encode. Line 4 should be answer ← decode(code, key).
Q2
B — The secret message is text, so it needs quote marks. Line 2 should be message ← "BAC".
Q3
C — Turning a picture row into 0s and 1s is encoding, not decoding. Line 3 should be code ← encode(row, key).
Q4
C — Decoding needs the key to know what each number means. Line 3 should be row ← decode(code, key).
Q5
A — A and B share the number 1, so you could not decode it back. Each letter needs its own number. Line 1 should be key ← A=1, B=2, C=3.