tet.util.base64 module
Base64 and Crockford Base32 encoding utilities.
This module provides encoding utilities including standard Base64 and Crockford’s Base32, which is human-friendly (avoids ambiguous characters like 0/O and 1/I/L).
Example
Using standard Base64:
from tet.util.base64 import Base64
encoded = Base64.encode(b"hello")
decoded = Base64.decode(encoded)
# Generate random Base64 characters
random_str = Base64.generate_characters(16)
Using Crockford Base32:
from tet.util.base64 import CrockfordBase32
encoded = CrockfordBase32.encode(b"hello")
decoded = CrockfordBase32.decode(encoded)
# Crockford Base32 is case-insensitive and handles ambiguous chars
CrockfordBase32.decode("O1L") # Treated as "011"
- class tet.util.base64.Base64[source]
Bases:
BaseCodecStandard Base64 encoding.
- chars = b'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/'
- padding = True
- class tet.util.base64.CrockfordBase32[source]
Bases:
BaseCodecCrockford’s Base32 encoding.
Human-friendly encoding that avoids ambiguous characters (0/O, 1/I/L). Case-insensitive and handles common transcription errors.
- chars = '0123456789ABCDEFGHJKMNPQRSTVWXYZ'
- classmethod decode(string, normalize=True, validate=False)[source]
Decode Crockford Base32 to bytes.
- classmethod encode(string, normalize=True, validate=False)[source]
Encode bytes to Crockford Base32.
- classmethod normalize(string)[source]
Normalize input by handling ambiguous characters (O->0, I/L->1).
- padding = False
- tet.util.base64.maketrans(frm, to, /)
Return a translation table useable for the bytes or bytearray translate method.
The returned table will be one where each byte in frm is mapped to the byte at the same position in to.
The bytes objects frm and to must be of the same length.