Skip to content
Snippets Groups Projects

z-base32 encoder

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by Frank Sauerburger

    Python 3 compatible, pure-Python implementation of z-base-32 based on Python's base64 module.

    Edited
    zbase32.py 532 B
    import base64
    
    original_alph = b"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"
    zbase_alph    = b"ybndrfg8ejkmcpqxot1uwisza345h769"
    
    encode_trans = bytes.maketrans(original_alph, zbase_alph)
    decode_trans = bytes.maketrans(zbase_alph, original_alph)
    
    def encode(value):
        """Encode the given value in zbase32"""
        encoded = base64.b32encode(value)
        return encoded.translate(encode_trans)
        
    def decode(value):
        """Decode a zbase32-encoded value"""
        translated = value.translate(decode_trans)
        return base64.b32decode(translated)
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment