Base32

Base32 is the base-32 numeral system. It uses a set of 32 digits, each of which can be represented by 5 bits (25). Since base32 is not very widely adopted, the question of notation—which characters to use to represent the 32 digits—is not as settled as in the case of more well-known numeral systems (such as hexadecimal), though RFCs and standards exist. One way to represent Base32 numbers in a human-readable way is by using the digits 0–9 and the twenty-two upper-case letters A–V. However, many other variations are used in different contexts. Historically, Baudot code could be considered a modified (stateful) base32 code.

The rest of this article discusses the use of Base32 for representing byte strings, not unsigned integer numbers, similar to the way Base64 works.

This is an example of a Base32 representation using the previously described 32-character set (IPFS CIDv1 in Base32 upper-case encoding): BAFYBEICZSSCDSBS7FFQZ55ASQDF3SMV6KLCW3GOFSZVWLYARCI47BGF354

Advantages

Base32 has a number of advantages over Base64:

  1. The resulting character set is all one case, which can often be beneficial when using a case-insensitive filesystem, DNS names, spoken language, or human memory.
  2. The result can be used as a file name because it cannot possibly contain the '/' symbol, which is the Unix path separator.
  3. The alphabet can be selected to avoid similar-looking pairs of different symbols, so the strings can be accurately transcribed by hand. (For example, the RFC 4648 symbol set omits the digits for one, eight and zero, since they could be confused with the letters 'I', 'B', and 'O'.)
  4. A result excluding padding can be included in a URL without encoding any characters.
  5. 5-bit allows storing 2 more characters per 32-bit integer (for a total of 6 instead of 4 with 2 bits to spare), saving bandwidth in constrained domains such as radiomeshes.

Base32 also has advantages over hexadecimal/Base16:

  1. Base32 representation takes 20% less space. (1000 bits takes 200 characters, compared with 250 for Base16.)

Disadvantages

Base32 representation takes roughly 20% more space than Base64. Also, because it encodes 5 bytes to 8 characters (rather than 3 bytes to 4 characters), padding to an 8-character boundary is a greater burden on short messages (which may be a reason to elide padding, which is an option in RFC 4648).

Length of notations as percentage of binary data
Base64 Base32 Hexadecimal
8-bit133%160%200%
7-bit117%140%175%

Even if Base32 takes roughly 20% less space than hexadecimal, Base32 is much less used. Hexadecimal can easily be mapped to bytes because two hexadecimal digits is a byte. Base32 does not map to individual bytes. Hexadecimal is also easier to learn and remember.

RFC 4648 Base32 alphabet

The most widely used Base32 alphabet is defined in RFC 4648 or the earlier RFC 3548, originally designed by John Myers for SASL/GSSAPI.[1] It uses an alphabet of AZ, followed by 27. The digits 0, 1 and 8 are skipped due to their similarity with the letters O, I and B (thus "2" has a decimal value of 26).

In some circumstances padding is not required or used (the padding can be inferred from the length of the string modulo 8). RFC 4648 states that padding must be used unless the specification of the standard (referring to the RFC) explicitly states otherwise. Excluding padding is useful when using Base32 encoded data in URL tokens or file names where the padding character could pose a problem.

The RFC 4648 Base32 alphabet
Value Symbol Value Symbol Value Symbol Value Symbol
0A8I16Q24Y
1B9J17R25Z
2C10K18S262
3D11L19T273
4E12M20U284
5F13N21V295
6G14O22W306
7H15P23X317
padding =

Alternative versions

Changing the Base32 alphabet, all alternative standards have similar combinations of alphanumeric symbols.

z-base-32

z-base-32[2] is a Base32 encoding designed by Zooko Wilcox-O'Hearn to be easier for human use and more compact. It includes 1, 8 and 9 but excludes l, v and 2. It also permutes the alphabet so that the easier characters are the ones that occur more frequently. It compactly encodes bitstrings whose length in bits is not a multiple of 8 and omits trailing padding characters. z-base-32 was used in the Mnet open source project, and is currently used in Phil Zimmermann's ZRTP protocol, and in the Tahoe-LAFS open source project.

z-base-32 alphabet
Value Symbol Value Symbol Value Symbol Value Symbol
0y8e16o24a
1b9j17t253
2n10k181264
3d11m19u275
4r12c20w28h
5f13p21i297
6g14q22s306
7815x23z319

Crockford's Base32

Another alternative design for Base32 is created by Douglas Crockford, who proposes using additional characters for a mod-37 checksum.[3] It excludes the letters I, L, and O to avoid confusion with digits. It also excludes the letter U to reduce the likelihood of accidental obscenity.

Libraries to encode binary data in Crockford's Base32 are available in a variety of languages.

Crockford's Base32 alphabet
Value Encode Digit Decode Digit Value Encode Digit Decode Digit
000 o O16Gg G
111 i I l L17Hh H
22218Jj J
33319Kk K
44420Mm M
55521Nn N
66622Pp P
77723Qq Q
88824Rr R
99925Ss S
10Aa A26Tt T
11Bb B27Vv V
12Cc C28Ww W
13Dd D29Xx X
14Ee E30Yy Y
15Ff F31Zz Z

Electrologica

An earlier form of base 32 notation was used by programmers working on the Electrologica X1 to represent machine addresses. The "digits" were represented as decimal numbers from 0 to 31. For example, 12-16 would represent the machine address 400 (= 12 × 32 + 16).

base32hex

Triacontakaidecimal is another alternative design for Base 32, which extends hexadecimal in a more natural way and was first proposed by Christian Lanctot, a programmer working at Sage software, in a letter to Dr. Dobb's magazine in March 1999[4] as a proposed solution for solving the Y2K bug and referred to as "Double Hex". This version was described in RFC 2938 under the name "Base-32". RFC 4648, while acknowledging existing use of this version in NSEC3, refers to it as base32hex and discourages labelling it as "base32".

Similarly to hexadecimal, the digits used are 0-9 followed by consecutive letters of the alphabet. This matches the digits used by the JavaScript parseInt() function[5] and the Python int() constructor[6] when a base larger than 10 (such as 16 or 32) is specified. It also retains hexadecimal's property of preserving bitwise sort order of the represented data, unlike RFC 4648's base-32 or base-64.[7]

Unlike many other base 32 notation systems, triacontakaidecimal is contiguous and includes characters that may visually conflict. With the right font it is possible to visually distinguish between 0, O and 1, I. Other fonts are unsuitable because the context that English usually provides is not provided by a notation system that is expressing numbers. However, the choice of font is not controlled by notation or encoding which is why it's risky to assume a distinguishable font will be used.

The "Extended Hex" Base 32 Alphabet
ValueSymbol ValueSymbol ValueSymbol ValueSymbol
009918I27R
1110A19J28S
2211B20K29T
3312C21L30U
4413D22M31V
5514E23N
6615F24O
7716G25P
8817H26Qpad=

Geohash

See Geohash algorithm, used to represent latitude and longitude values in one (bit-interlaced) positive integer.[8] The base32 representation of Geohash uses all decimal digits (0–9) and almost all of the lower case alphabet, except letters "a", "i", "l", "o", as shown by the following character map:

Decimal 0123456789101112131415
Base 32 0123456789bcdefg
 
Decimal 16171819202122232425262728293031
Base 32 hjkmnpqrstuvwxyz

Video games

Before NVRAM became universal, several video games for Nintendo platforms used base 31 numbers for passwords. These systems omit vowels (except Y) to prevent the game from accidentally giving a profane password. Thus, the characters are generally some minor variation of the following set: 0–9, B, C, D, F, G, H, J, K, L, M, N, P, Q, R, S, T, V, W, X, Y, Z, and some punctuation marks. Games known to use such a system include Mario Is Missing!, Mario's Time Machine, Tetris Blast, and The Lord of the Rings (Super NES).

Word-safe alphabet

The word-safe Base32 alphabet is an extension of the Open Location Code Base20 alphabet. That alphabet uses 8 numeric digits and 12 case-sensitive letter digits chosen to avoid accidentally forming words. Treating the alphabet as case-sensitive produces a 32 (8+12+12) digit set.

Decimal 0123456789101112131415
Base 32 23456789CFGHJMPQ
 
Decimal 16171819202122232425262728293031
Base 32 RVWXcfghjmpqrvwx

Software

Base32 is a notation for encoding arbitrary byte data using a restricted set of symbols that can be conveniently used by humans and processed by computers.

Base32 consists of a symbol set made up of 32 different characters, as well as an algorithm for encoding arbitrary sequences of 8-bit bytes into the Base32 alphabet. Because more than one 5-bit Base32 symbol is needed to represent each 8-bit input byte, it also specifies requirements on the allowed lengths of Base32 strings (which must be multiples of 40 bits). The closely related Base64 system, in contrast, uses a set of 64 symbols.

Base32 implementations in C/C++,[9][10] Perl,[11] Java,[12] JavaScript[13] Python,[14] Go[15] and Ruby[16] are available. [17]

See also

"Powers of 2" related bases:      Other bases:      Applications of base32:

References

  1. Myers, J. (May 23, 2000). SASL GSSAPI mechanisms. I-D draft-ietf-cat-sasl-gssapi-01. Retrieved 2023-06-24.
  2. O'Whielacronx, Zooko (2009). "Human-oriented base-32 encoding".
  3. Douglas Crockford. "Base 32". Archived from the original on 2002-12-23.
  4. Lanctot, Christian (1999-03-01). "A Better Date? (second letter under that heading) - Letters". Dr Dobb's.
  5. "parseInt() - JavaScript". MDN Web Docs. Mozilla.
  6. "Built-in Functions". Python documentation. Python Software Foundation. Archived from the original on 2018-10-26. Retrieved 2017-08-09.
  7. Josefsson, Simon (2006). "7. Base 32 Encoding with Extended Hex Alphabet". RFC 4648: The Base16, Base32, and Base64 Data Encodings. IETF. doi:10.17487/RFC4648.
  8. "Tips & Tricks - geohash.org". geohash.org. Retrieved 2020-04-03.
  9. "CyoEncode". SourceForge.
  10. "Gnulib - GNU Portability Library - GNU Project - Free Software Foundation". www.gnu.org.
  11. "MIME-Base32 - Base32 encoder and decoder". MetaCPAN. Retrieved 2018-07-29.
  12. "Base32 (Apache Commons Codec 1.15 API)". commons.apache.org.
  13. "base32". npm.
  14. "base64 — Base16, Base32, Base64, Base85 Data Encodings". Python documentation.
  15. "Base32 package - encoding/Base32 - PKG.go.dev".
  16. "base32 | RubyGems.org | your community gem host". rubygems.org.
  17. "String To Hex Converter". Beautify Code.
This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.