Small inputs, big assumptions

A tiny property check that makes an encoding contract explicit.

The challenge

A fictional utility encodes a byte sequence into Base64 and decodes it again. Its contract is a round trip: decoded bytes must exactly equal the original input.

State the property

import base64

cases = [b"", b"a", b"\x00\xff", "București".encode("utf-8")]

for original in cases:
    encoded = base64.b64encode(original)
    restored = base64.b64decode(encoded, validate=True)
    assert restored == original

print("All round trips preserved the original bytes")

What this does not prove

The check only verifies the selected cases. It does not establish that an entire protocol is correct, that inputs have a trusted origin, or that an encoded secret is protected.

Base64 is an encoding, not encryption.

Lessons learned

Separate bytes from text, specify the encoding at boundaries, and include empty and non-ASCII inputs in a reproducible test.