Python base64 a85decode














































Python base64 a85decode



Python base64 A85decode METHOD

A85decode method is a part of python's Lib/base64.py module. This module provides functionality for encoding binary data to printable ASCII characters and decoding such encodings back to binary, read more about the module here.There are two interfaces provided by this module. A85decode method is a part of modern interface. The modern interface supports encoding bytes-like objects to ASCII bytes, and decoding bytes-like objects or strings containing ASCII to bytes.

a85decode(b,*,foldspaces=False,adobe=False,ignorechars=b' \t\n\v')

Arguments

b = Bytes-like object or byte string
foldspaces = Optional bool value (True/False)
adobe = Optional bool value (True/False)
ignorechars = Bytes-like characters

Description

This method decodes Ascii85 encoded bytes-like object or ASCII string provided in the argument b, and returns the decoded bytes. Both Base85 and Ascii85 have an expansion factor of 5 to 4 (5 Base85 or Ascii85 characters can encode 4 binary bytes), while the better-known Base64 has an expansion factor of 6 to 4. They are therefore more efficient when space expensive. They differ by details such as the character map used for encoding.
The second argument in this method is named "foldspaces". It is an optional flag set to False by default. It accepts boolean value and uses a special short sequence 'y' instead of 4 consecutive spaces (ASCII 0x20) as supported by 'btoa'. This feature is not supported by the "standard" Ascii85 encoding.
The third argument in this method is named "adobe". This is also an additional argument that takes in boolean values. Adobe controls whether the input sequence is in Adobe Ascii85 format i.e. it controls whether the encoded byte sequence is framed with <~ and ~>, which is used by the Adobe implementation.
The final argument in this method is "ignorechars". It takes in bytes-like object or ASCII string and is default set to characters b"\t", b"\n", b"\v". The input provided in this argument marks the character to be ignored in the encoded string. This should only contain whitespace characters, and by default contains all whitespace characters in ASCII.
Character mapping used by Ascii85 are
!"#$%&'()*+,-./0123456789:;<=>?@
ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_
abcdefghijklmnopqrstu

Limitations

  • Input argument b and ignorechars should be a byte like object or a byte string
  • Input argument foldspaces and adobe should be a bool value

Usage

>>> import base64

>>> encoded_string = b';IOHRDf$UqFE2)5B)'
>>>
print
(base64.a85decode(encoded_string))
b'Random String'

>>> encoded_string = b'y+9'
>>>
print
(base64.a85decode(encoded_string,foldspaces=True))
b' '

>>> encoded_string = b'<~;IOHRDf$UqFE2)5B)~>'
>>>
print
(base64.a85decode(encoded_string,adobe=True))
b'Random String'

>>> encoded_string = a =b';\nI\nO\nH\nR\nD\nf$\nUqF\nE\n2)\n5\nB)'
>>>
print
(base64.a85decode(encoded_string,ignorechars=b"\n"))
b'Random String'

Note

If an input more than the allowed size is used the following error will occur
ValueError: Ascii85 overflow
If a character outside of character mapping is used the following error will occur
ValueError: Non-Ascii85 digit found: {
If a wrong argument type like int is used as input the following error will occur
TypeError: argument should be a bytes-like object or ASCII string, not 'int'
If no input is provided as an argument the following error will occur
TypeError: a85decode() missing 1 required positional argument: 'b'

Comments