Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Ascii85

From Wikipedia, the free encyclopedia
(Redirected fromBTOA)
Form of binary-to-text encoding developed by Paul E. Rutter

Ascii85, also calledBase85, is a form ofbinary-to-text encoding developed by Paul E. Rutter for thebtoa utility. By using fiveASCII characters to represent four bytes ofbinary data (making the encoded size14 larger than the original, assuming eight bits per ASCII character), it is more efficient thanuuencode orBase64, which use four characters to represent three bytes of data (13 increase, assuming eight bits per ASCII character).

Its main modern uses are inAdobe'sPostScript andPortable Document Format file formats, as well as in thepatch encoding forbinary files used byGit.[1]

Overview

[edit]

The basic need for a binary-to-text encoding comes from a need to communicate arbitrarybinary data over preexistingcommunications protocols that were designed to carry only English languagehuman-readable text. Those communication protocols may only be 7-bit safe (and within that avoid certain ASCII control codes), and may requireline breaks at certain maximum intervals, and may not maintainwhitespace. Thus, only the 94printable ASCII characters are "safe" to use to convey data.

Eighty-five is the minimum integer value ofn such thatn5 ≥ 2564; soany sequence of 4 bytes can be encoded as 5 symbols, as long as at least 85 distinct symbols are available. (Fiveradix-85 digits can represent the integers from 0 to 4,437,053,124 inclusive, which suffice to represent all 4,294,967,296 possible 4-byte sequences.)

Characters used by the encoded text are!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstu and additionallyz to mark a sequence of four zero bytes.

Encoding

[edit]
This sectiondoes notcite anysources. Please helpimprove this section byadding citations to reliable sources. Unsourced material may be challenged andremoved.(March 2023) (Learn how and when to remove this message)

When encoding, each group of 4 bytes is taken as a 32-bit binary number, most significant byte first (Ascii85 uses abig-endian convention). This is converted, by repeatedly dividing by 85 and taking the remainder, into 5 radix-85 digits. Then each digit (again, most significant first) is encoded as an ASCII printable character by adding 33 to it, giving the ASCII characters 33 (!) through 117 (u).

Because all-zero data is quite common, an exception is made for the sake ofdata compression, and an all-zero group is encoded as a single characterz instead of!!!!!.

Groups of characters that decode to a value greater than232 − 1 (encoded ass8W-!) will cause a decoding error, as willz characters in the middle of a group. White space between the characters is ignored and may occur anywhere to accommodate line-length limitations.

Limitations

[edit]

The original specification only allows a stream that is a multiple of 4 bytes to be encoded.

Encoded data may containcharacters that have special meaning in many programming languages and in some text-based protocols, such as left-angle-bracket<, backslash\, and the single and double quotes' &". Other base-85 encodings like Z85 andRFC 1924 are designed to be safe in source code.[2]

History

[edit]

btoa version

[edit]
"btoa" redirects here. For the JavaScriptbtoa() function, seeBase64.

The original btoa program always encoded full groups (padding the source as necessary), with a prefix line of "xbtoa Begin", and suffix line of "xbtoa End", followed by the original file length (in decimal andhexadecimal) and three 32-bitchecksums. The decoder needs to use the file length to see how much of the group was padding. The initial proposal for btoa encoding used an encoding alphabet starting at the ASCII space character through "t" inclusive, but this was replaced with an encoding alphabet of "!" to "u" to avoid "problems with some mailers (stripping off trailing blanks)".[3] This program also introduced the special "z" short form for an all-zero group. Version 4.2 added a "y" exception for a group of all ASCIIspace characters (0x20202020).

ZMODEM version

[edit]

"ZMODEM Pack-7 encoding" encodes groups of 4 octets into groups of 5 printable ASCII characters in a similar, or possibly in the same way as Ascii85 does. When aZMODEM program sends pre-compressed 8-bit data files over7-bit data channels, it uses "ZMODEM Pack-7 encoding".[4]

Adobe version

[edit]

Adobe adopted the basic btoa encoding, but with slight changes, and gave it the name Ascii85. The characters used are the ASCII characters 33 (!) through 117 (u) inclusive (to represent the base-85 digits 0 through 84), together with the letterz (as a special case to represent a 32-bit 0 value), and white space is ignored. Adobe uses the delimiter "~>" to mark the end of an Ascii85-encoded string and represents the length by truncating the final group: If the last block of source bytes contains fewer than 4 bytes, the block is padded with up to 3 null bytes before encoding. After encoding, as many bytes as were added as padding are removed from the end of the output.

The reverse is applied when decoding: The last block is padded to 5 bytes with the Ascii85 characteru, and as many bytes as were added as padding are omitted from the end of the output (see example).

The padding is not arbitrary. Converting from binary to base 64 only regroups bits and does not change them or their order (a high bit in binary does not affect the low bits in the base64 representation). In converting a binary number to base85 (85 isnot a power of two) high bits do affect the low order base85 digits and conversely. Padding the binary low (with zero bits) while encoding and padding the base85 value high (withus) in decoding assures that the high order bits are preserved (the zero padding in the binary gives enough room so that a small addition is trapped and there is no "carry" to the high bits).

In Ascii85-encoded blocks, whitespace and line-break characters may be present anywhere, including in the middle of a 5-character block, but they must be silently ignored.

Adobe's specification does not support they exception.

Example for Ascii85

[edit]

A quote fromThomas Hobbes'sLeviathan:

Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.

If this is initially encoded using US-ASCII, it can be reencoded in Ascii85 as follows:

9jqo^BlbD-BleB1DJ+*+F(f,q/0JhKF<GL>Cj@.4Gp$d7F!,L7@<6@)/0JDEF<G%<+EV:2F!,O<DJ+*.@<*K0@<6L(Df-\0Ec5e;DffZ(EZee.Bl.9pF"AGXBPCsi+DGm>@3BB/F*&OCAfu2/AKYi(DIb:@FD,*)+C]U=@3BN#EcYf8ATD3s@q?d$AftVqCh[NqF<G:8+EV:.+Cf>-FD5W8ARlolDIal(DId<j@<?3r@:F%a+D58'ATD4$Bl@l3De:,-DJs`8ARoFb/0JMK@qB4^F!,R<AKZ&-DfTqBG%G>uD.RTpAKYo'+CT/5+Cei#DII?(E,9)oF*2M7/c
Text contentMan...
ASCII77 (0x4d)97 (0x61)110 (0x6e)32 (0x20)...
Bit pattern01001101011000010110111000100000...
32-bit value1,298,230,816 = 24×854 + 73×853 + 80×852 + 78×85 + 61...
Base 85 (+33)24 (57)73 (106)80 (113)78 (111)61 (94)...
ASCII9jqo^...
Text contentsure
ASCII115 (0x73)117 (0x75)114 (0x72)101 (0x65)
Bit pattern01110011011101010111001001100101
32-bit value1,937,076,837 = 37×854 + 9×853 + 17×852 + 44×85 + 22
Base 85 (+33)37 (70)9 (42)17 (50)44 (77)22 (55)
ASCIIF*2M7


Since the last 4-tuple is incomplete, it must be padded with three zero bytes:

Text content.\0\0\0
ASCII46 (0x2e)0 (0x00)0 (0x00)0 (0x00)
Bit pattern00101110000000000000000000000000
32-bit value771,751,936 = 14×854 + 66×853 + 56×852 + 74×85 + 46
Base 85 (+33)14 (47)66 (99)56 (89)74 (107)46 (79)
ASCII/cYkO

Since three bytes of padding had to be added, the three final characters 'YkO' are omitted from the output.

Decoding is done inversely, except that the last 5-tuple is padded with 'u' characters:

ASCII/cuuu
Base 85 (+33)14 (47)66 (99)84 (117)84 (117)84 (117)
32-bit value771,955,124 = 14×854 + 66×853 + 84×852 + 84×85 + 84
Bit pattern00101110000000110001100110110100
ASCII46325180
Text content.[ETX ][EM ]´ (Extended ASCII)

Since the input had to be padded with three 'u' bytes, the last three bytes of the output are ignored and we end up with the original period.

The input sentence does not contain 4 consecutive zero bytes, so the example does not show the use of the 'z' abbreviation.

Compatibility

[edit]

The Ascii85 encoding is compatible with 7-bit and 8-bitMIME, while having less overhead thanBase64.

One potential compatibility issue of Ascii85 is that some of the characters it uses are significant in markup languages such asXML orSGML. To include Ascii85 data in these documents, it may be necessary to escape thequote,angle brackets, andampersands.

RFC 1924 version

[edit]

Published onApril 1, 1996, informationalRFC 1924: "A Compact Representation of IPv6 Addresses" byRobert Elz suggests a base-85 encoding ofIPv6 addresses as anApril Fools' Day joke. This differs from the scheme used above in that he proposes a different set of 85 ASCII characters, and proposes to do all arithmetic on the 128-bit number, converting it to a single 20-digit base-85 number (internal whitespace not allowed), rather than breaking it into four 32-bit groups.

The proposed character set is, in order,09,AZ,az, and then the 23 characters!#$%&()*+-;<=>?@^_`{|}~. The highest possible representable address, 2128−1 = 74×8519 + 53×8518 + 5×8517 + ..., would be encoded as=r54lj&NUUO~Hi%c2ym0.

This character set excludes the characters"',./:[\] , making it suitable for use inJSON strings (where" and\ would require escaping). However, for SGML-based protocols, notably including XML, string escapes may still be required (to accommodate<,> and&).

See also

[edit]

References

[edit]
  1. ^Hamano, Junio C (May 5, 2006)."[PATCH] binary patch".git. Archived fromthe original on 2020-07-26.
  2. ^"32/Z85" on ZeroMQ RFC
  3. ^Orost, Joe (Mar 26, 1991)."Re: COMPRESSING of binary data into mailable ASCII Re: Encoding of binary data into mailable ASCII".Google Groups. Retrieved11 April 2015.
  4. ^Chuck Forsberg."Recent Developments in ZMODEM".omen.com. Archived fromthe original on 2015-09-24. Retrieved2013-05-14.. "ZMODEM Pack-7 packs 4 bytes into 5 printing characters."

External links

[edit]
Human readable
Binary
Retrieved from "https://en.wikipedia.org/w/index.php?title=Ascii85&oldid=1277958653#btoa_version"
Category:
Hidden categories:

[8]ページ先頭

©2009-2025 Movatter.jp