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

Function ascii85_decode

ciphers/base85.py:33–52  ·  view source on GitHub ↗

>>> ascii85_decode(b"") b'' >>> ascii85_decode(b"0etOA2#") b'12345' >>> ascii85_decode(b"@UX=h+?24") b'base 85'

(data: bytes)

Source from the content-addressed store, hash-verified

31
32
33def ascii85_decode(data: bytes) -> bytes:
34 """
35 >>> ascii85_decode(b"")
36 b''
37 >>> ascii85_decode(b"0etOA2#")
38 b'12345'
39 >>> ascii85_decode(b"@UX=h+?24")
40 b'base 85'
41 """
42 null_values = 5 * ((len(data) // 5) + 1) - len(data)
43 binary_data = data.decode("utf-8") + "u" * null_values
44 b85_chunks = map("".join, zip(*[iter(binary_data)] * 5))
45 b85_segments = [[ord(_s) - 33 for _s in chunk] for chunk in b85_chunks]
46 results = [bin(_base85_to_10(chunk))[2::].zfill(32) for chunk in b85_segments]
47 char_chunks = [
48 [chr(int(_s, 2)) for _s in map("".join, zip(*[iter(r)] * 8))] for r in results
49 ]
50 result = "".join("".join(char) for char in char_chunks)
51 offset = int(null_values % 5 == 0)
52 return bytes(result[: offset - null_values], "utf-8")
53
54
55if __name__ == "__main__":

Callers

nothing calls this directly

Calls 2

_base85_to_10Function · 0.85
decodeMethod · 0.45

Tested by

no test coverage detected