Python 3.10+base64function
base64.b32hexencode()
Base32 and Base16
Base32 with the extended hex alphabet 0–9 and A–V. Encoded strings sort in the same order as the original bytes.
Syntax
base64.b32hexencode(s)
The key difference from b32encode is ordering: in plain Base32 the digits 2–7 come after the letters in the encoding alphabet but before them in ASCII, so sorting encoded strings breaks. The base32hex alphabet is ordered like ASCII, and comparing strings matches comparing bytes. Read the result with the matching b32hexdecode, not b32decode.
Examples
import base64
print(base64.b32encode(b'\x00'), base64.b32encode(b'\xff')) # → b'AA======' b'74======' — порядок перевёрнут
print(base64.b32hexencode(b'\x00'), base64.b32hexencode(b'\xff')) # → b'00======' b'VS======'
See also
Open in the full glossarydocs.python.orgReport an inaccuracy