Python Glossary Русский

Python 3.10+base64function

base64.b32hexdecode()

Base32 and Base16

Decodes Base32 in the base32hex alphabet (0–9, A–V). The counterpart of b32hexencode; it has no map01 parameter.

Syntax

base64.b32hexdecode(s, casefold=False)

A plain Base32 string gives different bytes or an error here: the alphabets overlap, but the characters mean different values, so mixing the functions up is especially dangerous. There is no map01 because 0 and 1 are legitimate digits in this alphabet. As with b32decode, lowercase letters are accepted only with casefold=True.

Examples

import base64
print(base64.b32hexdecode(b'D1KG===='))  # → b'hi'
print(base64.b32hexdecode(b'd1kg====', casefold=True))  # → b'hi'
print(base64.b32hexdecode(b'NBUQ===='))  # → b'\xba\xfd' — строка обычного Base32, байты другие

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy