Data Encoding Tutorials - Herong's Tutorial Examples - v5.23, by Herong Yang
Base32 Encoding Algorithm
This section describes the Base32 encoding algorithm with some simple encoding examples.
Base32 encoding algorithm is designed to encode any binary data, an stream of bytes, into a stream of 32-printable characters.
Comparing with Base64 encoding, Base32 uses a much smaller set of characters which has three main advantages:
Obviously, the main disadvantage of Base32 is that the resulting string is about 20% longer than Base64.
The most widely used Base32 character set is defined in RFC 3548. It uses an alphabet of A-Z, followed by 2-7. 0 and 1 are skipped due to their similarity with the letters O and I. Those 32 characters are mapped to integer values are below:
Value Encoding Value Encoding Value Encoding Value Encoding 0 A 9 J 18 S 27 3 1 B 10 K 19 T 28 4 2 C 11 L 20 U 29 5 3 D 12 M 21 V 30 6 4 E 13 N 22 W 31 7 5 F 14 O 23 X 6 G 15 P 24 Y 7 H 16 Q 25 Z 8 I 17 R 26 2
The Base32 encoding process is to:
Example 1: Input data: 1 byte, "A". Encoded output: 8 characters, "IE======"
Input Data A Input Bits 01000001 Padding 01000001 00000000 00000000 00000000 00000000 \ | \ | | \ \ Bit Groups 01000 00100 00000 00000 00000 00000 00000 00000 Mapping I E A A A A A A Overriding I E = = = = = =
Example 2: Input data: 2 bytes, "AB". Encoded output, 8 characters, "IFBA===="
Input Data A B Input Bits 01000001 01000010 Padding 01000001 01000010 00000000 00000000 00000000 \ | \ | | \ \ Bit Groups 01000 00101 00001 00000 00000 00000 00000 00000 Mapping I F B A A A A A Overriding I F B A = = = =
Example 3: Input data: 3 bytes, "ABC". Encoded output, 8 characters, "IFBEG==="
Input Data A B C Input Bits 01000001 01000010 01000011 Padding 01000001 01000010 01000011 00000000 00000000 \ | \ | | \ \ Bit Groups 01000 00101 00001 00100 00110 00000 00000 00000 Mapping I F B E G A A A Overriding I F B E G = = =
Example 4: Input data: 4 bytes, "ABCD". Encoded output, 8 characters, "IFBEGRA="
Input Data A B C D Input Bits 01000001 01000010 01000011 01000100 Padding 01000001 01000010 01000011 01000100 00000000 \ | \ | | \ \ Bit Groups 01000 00101 00001 00100 00110 10001 00000 00000 Mapping I F B E G R A A Overriding I F B E G R A =
Example 5: Input data: 5 bytes, "ABCDE". Encoded output, 8 characters, "IFBEGRCF"
Input Data A B C D E Input Bits 01000001 01000010 01000011 01000100 01000101 Padding 01000001 01000010 01000011 01000100 01000101 \ | \ | | \ \ Bit Groups 01000 00101 00001 00100 00110 10001 00010 00101 Mapping I F B E G R C F Overriding I F B E G R C F
Table of Contents
Base64 Encoding and Decoding Tools
Base64URL - URL Safe Base64 Encoding
Bitpedia Implementation of Base32 in Java
Bitpedia Implementation of Base32 in Java - Test
Andre's Implementation of Base32 in PHP
Andre's Implementation of Base32 in PHP - Test
madebits Implementation of Base32 in C++