Encode binary bytes for a text boundary
Base64 represents arbitrary bytes using an ASCII alphabet. It is useful when a text-only format must carry a small binary value. Encoding does not require the original bytes to be valid UTF-8, and decoding should recover those exact bytes.
Choose validation deliberately when accepting encoded input. A permissive decoder may discard characters that your protocol should reject. Base64 changes representation; the original data remains recoverable by anyone with the encoded text. Keep the bytes-to-text conversion separate from interpreting the decoded payload as a file, image or other application-specific format.
import base64
raw = bytes([0, 255, 42])
text = base64.b64encode(raw).decode("ascii")
print(text)
print(base64.b64decode(text, validate=True))Your task
Implement encode_blob(raw) returning standard Base64 ASCII text, and decode_blob(text) returning the original bytes with strict alphabet validation. Support empty bytes and binary values that are not UTF-8.
The explanation opens here once every check passes.