binascii hexlify Formats Bytes and b85 Packs Text

Format binary digests with delimiter support via binascii.hexlify and pack bytes compactly with base64.b85encode compared against Base64 overhead.

PythonData Integrity

Code

snippet
import base64
import binascii

mac_bytes = bytes.fromhex("a45e60c219f0")

# binascii.hexlify supports sep (Python 3.8+) to format byte groups directly
colon_mac = binascii.hexlify(mac_bytes, sep=":").decode("ascii")
roundtrip = binascii.unhexlify(colon_mac.replace(":", ""))
print("mac:", colon_mac, "| roundtrip ok:", roundtrip == mac_bytes)

# Base85 uses a 5:4 expansion (25% overhead) vs Base64's 4:3 (33% overhead)
payload = b"frame-header-0123456789-checksum"
b64 = base64.b64encode(payload)
b85 = base64.b85encode(payload)
print(f"raw={len(payload)}B b64={len(b64)}B b85={len(b85)}B")
print("b85 sample:", b85.decode("ascii"), "| decoded ok:", base64.b85decode(b85) == payload)

Output

Captured from a sandboxed run of this snippet in the build pipeline.

mac: a4:5e:60:c2:19:f0 | roundtrip ok: True
raw=32B b64=44B b85=40B
b85 sample: W^!R|Wi4oBVPs`;Eif@MGc+|eH#j*hV`yb#YjbsN | decoded ok: True

Behavior overview — binascii hexlify Formats Bytes and b85 Packs Text

Top-level bindings mac_bytes, colon_mac, roundtrip, payload hold the demo state — nothing sits inside a function scope.

What to watch for

  • The whole dependency story is the language version itself.

Using it

The demo output is labeled (mac:, raw=, b85 sample:); each label names the call that printed it.

Interactive Tools for This Topic

FAQ

What has to be installed first?
Nothing — the runtime itself provides everything the code touches. Every import resolves inside the standard library — `base64`, `binascii`. Its state lives in module-level bindings: `mac_bytes`, `colon_mac`, `roundtrip`.