MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / base32_decode

Function base32_decode

ciphers/base32.py:26–40  ·  view source on GitHub ↗

>>> base32_decode(b'JBSWY3DPEBLW64TMMQQQ====') b'Hello World!' >>> base32_decode(b'GEZDGNBVGY======') b'123456' >>> base32_decode(b'ONXW2ZJANRXW4ZZAMNXW24DMMV4CA43UOJUW4ZY=') b'some long complex string'

(data: bytes)

Source from the content-addressed store, hash-verified

24
25
26def base32_decode(data: bytes) -> bytes:
27 """
28 >>> base32_decode(b'JBSWY3DPEBLW64TMMQQQ====')
29 b'Hello World!'
30 >>> base32_decode(b'GEZDGNBVGY======')
31 b'123456'
32 >>> base32_decode(b'ONXW2ZJANRXW4ZZAMNXW24DMMV4CA43UOJUW4ZY=')
33 b'some long complex string'
34 """
35 binary_chunks = "".join(
36 bin(B32_CHARSET.index(_d))[2:].zfill(5)
37 for _d in data.decode("utf-8").strip("=")
38 )
39 binary_data = list(map("".join, zip(*[iter(binary_chunks)] * 8)))
40 return bytes("".join([chr(int(_d, 2)) for _d in binary_data]), "utf-8")
41
42
43if __name__ == "__main__":

Callers

nothing calls this directly

Calls 1

decodeMethod · 0.45

Tested by

no test coverage detected