Base64 is encoding, not encryption

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

Base64 is encoding, not encryption

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Base64 turns the text "Hi" into "SGk=". Which statement describes what Base64 is?
A Encoding: it rewrites data in a different form
B Encryption: it hides data using a secret key
2. Mia finds the text "cGFzc3dvcmQ=" in a file. Who can turn it back into the original text?
A Anyone, because Base64 has no secret key
B Only someone who knows the secret key
3. A developer stores user passwords as Base64 text. Is this a safe way to protect them?
A Yes, the characters look scrambled so they are protected
B No, anyone can decode Base64 straight away
4. Why is Base64 often used when sending files or images inside emails and web pages?
A It locks the data so interceptors cannot read it
B It rewrites data as printable text characters that can be sent as text
5. Which comparison of Base64 and hexadecimal (hex) is correct?
A Both are encodings that anyone can reverse without a key
B Base64 is an encoding but hex is a secure encryption

Match the Pairs

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

Left columnRight column
1base64.b64encode(b"Hi") ATreating Base64 as encryption. There is no key, so anyone can decode it and read the password.
2base64.b64decode("SGk=") BRewrites the bytes of Hi as Base64 text (SGk=). No key is used, so anyone can turn it back.
3Base64 uses only 64 printable characters, so binary data can travel as plain text. CA-Z a-z 0-9 + /
4Hex uses 16 characters for each 4 bits, while Base64 uses 64 characters for each 6 bits, so Base64 is shorter. DHi = 4869 (hex) or SGk= (Base64)
5secret = base64.b64encode(password) # now it is safe EBase64 is not encrypted and has no secret key. Anyone can decode SGVsbG8= to Hello.
6Encrypted with Base64: SGVsbG8= (only I can read it) FReverses Base64 text back to the original data (Hi) with no password or key needed.

Definitions

Base64

Fill in the Blanks

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

1.
import ______ msg = b"Hi" print(base64.b64encode(msg))
2.
import base64 coded = base64._________(b"Hello") print(coded)
3.
import base64 coded = "SGk=" print(base64._________(coded))
4.
text = "SGk=" data = base64.b64decode(____) print(data)
5.
data = b"Hi" print(data.___()) print(base64.b64encode(data))

Spot the Error

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

Question 1
A import base46
B msg = b'Hi'
C code = base64.b64encode(msg)
D print(code)
Question 2
A import base64
B pw = b'password1'
C enc = base64.b64encode(pw)
D print(base64.decrypt(enc))
Question 3
A import base64
B enc = 'SGk='
C raw = base64.b64encode(enc)
D print(raw)
Question 4
A import base64
B data = b'Hi'
C print(data.hexdigest())
D print(base64.b64encode(data))
Question 5
A import base64
B def encode(text, key):
C b = text.encode()
D return base64.b64encode(b)

Answer Key

Base64 is encoding, not encryption
Section A: Quick Questions
Q1
A — Encoding: it rewrites data in a different form
Q2
A — Anyone, because Base64 has no secret key
Q3
B — No, anyone can decode Base64 straight away
Q4
B — It rewrites data as printable text characters that can be sent as text
Q5
A — Both are encodings that anyone can reverse without a key
Section B: Match the Pairs
Q1
base64.b64encode(b"Hi") → Rewrites the bytes of Hi as Base64 text (SGk=). No key is used, so anyone can turn it back.
Q2
base64.b64decode("SGk=") → Reverses Base64 text back to the original data (Hi) with no password or key needed.
Q3
Base64 uses only 64 printable characters, so binary data can travel as plain text. → A-Z a-z 0-9 + /
Q4
Hex uses 16 characters for each 4 bits, while Base64 uses 64 characters for each 6 bits, so Base64 is shorter. → Hi = 4869 (hex) or SGk= (Base64)
Q5
secret = base64.b64encode(password) # now it is safe → Treating Base64 as encryption. There is no key, so anyone can decode it and read the password.
Q6
Encrypted with Base64: SGVsbG8= (only I can read it) → Base64 is not encrypted and has no secret key. Anyone can decode SGVsbG8= to Hello.
Section C: Definitions
Q1
Base64 — Rewrites data using 64 printable characters so it can be sent as text. It has no secret key, so anyone can reverse it. It is encoding, not encryption, and protects nothing.
Section D: Fill in the Blanks
Q1
import base64 msg = b"Hi" print(base64.b64encode(msg))
Q2
import base64 coded = base64.b64encode(b"Hello") print(coded)
Q3
import base64 coded = "SGk=" print(base64.b64decode(coded))
Q4
text = "SGk=" data = base64.b64decode(text) print(data)
Q5
data = b"Hi" print(data.hex()) print(base64.b64encode(data))
Section E: Spot the Error
Q1
A — The Python module is called base64, not base46. The first line should be import base64 so b64encode() can be used.
Q2
D — Base64 is encoding, not encryption, so there is no decrypt function and no key. Anyone can reverse it with base64.b64decode(enc).
Q3
C — To get the original data back you must decode, not encode again. Line 3 should be raw = base64.b64decode(enc), which needs no key.
Q4
C — Bytes have a .hex() method that writes them in hex (16 characters). hexdigest() belongs to hash objects, not bytes. Line 3 should be print(data.hex()).
Q5
B — Base64 has no secret key, so the function needs no key parameter. The line should be def encode(text):.