Ascii85 Encoder / Decoder

Convert text to and from Ascii85.

Result

87cURD_*#4DfTZ)+T

How it is calculated

Encoding reads the text as bytes and takes them in groups of 4. Each group is read as one 32-bit number n = b0·256³ + b1·256² + b2·256 + b3, which is written in base 85 as five digits; each digit d becomes the character with code d + 33, so the output uses the printable characters from ! to u. As PDF 32000-1 (7.4.3) specifies, a full group of four zero bytes is written as z instead of !!!!!. A last group of r bytes (fewer than 4) is padded with zero bytes and only the first r + 1 characters are kept, never as z. The output has no delimiters. Decoding reverses this: white space is ignored, a z between groups gives four zero bytes, the ~> end-of-data marker ends the data, characters are read in groups of 5, and a short last group is padded with u. Input is rejected, as the standard requires, if it has a character outside ! to u and z, a z inside a group, a group worth more than 2³² − 1, or a last group of one character. Non-ASCII letters take several bytes, so they give more characters.

Worked example

Encode Hello, World!, 13 bytes. The first group Hell is the number 1,214,606,444. In base 85 its digits are 23, 22, 66, 52, 49; adding 33 gives the characters 87cUR. The next groups o, W and orld are converted the same way, and the final single byte ! gives two characters. The full result is 87cURD_*#4DfTZ)+T, 18 characters for 13 bytes. Switching the mode to decode and pasting the result returns Hello, World!.

Try this example →

Common mistakes

  • Pasting Ascii85 with the <~ opening marker that some PostScript tools add. The closing ~> is understood, but remove the <~ first.
  • Expecting !!!!! for four zero bytes. The encoder writes z, as the PDF standard does; both decode the same.
  • Leaving the mode on encode when the text is already Ascii85. It is then encoded a second time, giving longer, different text.
  • Copying only part of an encoded string. A missing character changes the group alignment, and the output is garbled or empty.
  • Treating Ascii85 as encryption. It is only a reversible encoding that anyone can decode.

Sources

About this calculator

This calculator encodes text to Ascii85 (base85) or decodes it back, using the scheme that packs every 4 bytes of binary data into 5 printable ASCII characters — more space-efficient than Base64's 4-for-3 ratio, at the cost of a wider character set. It follows the ASCII85Decode filter of the PDF standard (ISO 32000-1, 7.4.3): a group of four zero bytes is written as the single character z, and when decoding, white space is ignored and the ~> end-of-data marker ends the input.

Developers working with PDF and PostScript files, where Ascii85 is a native filter, and anyone needing compact text-safe binary encoding, use it to embed binary data in text-only formats.

Was this helpful?

You can pick up to 3 reactions.

Note from the editors

As a size check, the 13-byte string Hello, World! becomes 17 characters here, four more than the input, whereas Base64 would need 20. Runs of zero bytes shrink further, because each group of four zeros is written as a single z, as the PDF standard specifies. The output uses punctuation that can break in URLs, JSON or shell strings. Which Ascii85 variant do you work with?

Comments

  • Be the first to comment.

Popular calculators

All Calculators