Base64

In Data-processing, base64 is a coding of information using 64 characters, selected to be available on the majority of the systems. It is mainly used for the transmission of messages (Email and messages of forum Usenet). It is defined as a coding MIME.

An alphabet of 65 characters is used to allow the representation of 6 bits by character. “=” (65e character) is used in the process of coding for the final characters.

The process of coding represents groups of 24 bits of data input by a chain at exit of 4 coded natures. While proceeding from left to right, a group of 24 bits is created by concaténant 3 bytes (8 bits per byte). These 24 bits are treated as 4 concaténés groups of 6 bits each one converted into a single character in the alphabet of base 64.

Each group of 6 bits is used as index in the table of the characters of base 64. The character referred by the corresponding index is used like coding of this group of 6 bits.

Value Coding Value Coding Value Coding Value Coding 0 17 R 34 I 51 Z has 1 B 18 S 35 J 52 0 2 C 19 T 36 K 53 1 3D 20 U 37 L 54 2 4th 21 V 38 m 55 3 5 F 22 W 39 N 56 4 6 G 23 X 40 O 57 5 7:24 Y 41 p 58 6 8 I 25 Z 42 Q 59 7 9 J 26 have 43 r 60 8 10 K 27 B 44 S 61 9 11 L 28 C 45 T 62 + 12 M 29 D 46 U 63/ 13 NR 30 E 47 v 14 O 31 F 48 W (complement) = 15 P 32 G 49 X 16 Q 33. 50 there

A special treatment is carried out so less than 24 bits available to the end them are given to code. No bit not remaining not-coded, so less than 24 bits are available then bits to zero are added to the right-hand side of the data to form an integer of groups of 6 bits. Since all the data coded input bases 64 of them of an integer of bytes alone three cases are consituées are possible:

  • if the last part of the data input is consituée of a multiple number of bits of 24, then the last group of characters of exit will be a multiple of 4 characters without complement with “=”;
  • if the last part of the data input makes 8 bits exactly, then the last group of characters of exit will be composed of two natures of coding followed by the two characters “=” (of complement);
  • if the last part of the data input makes 16 bits exactly, then the last group of characters of exit will be composed of three natures of coding followed by a character “=” (of complement).

Example

Let us take the group of 3 characters “ Hi! ”. Below the first line indicates into binary the equivalence of these 3 bytes. The transformation consists as one can see it, to separate the bits to form at exit 4 groups of 6 bits:

01001000 01101001 00100001 <=> 010010 000110 100100 100001

The 4 groups of 6 bits at exit give us values 18,6,36 and 33. Thus while following the correspondence of the indexed table we obtain the 4 characters “ SGkh ”.

External bonds

  • Source code out of C
  • Source code in Java
  • Source code in Javascript
  • Source code in C#
  • Source code in Perl
  • Graphical interface for Windows

Resources

  • Coder/Base64 Decoder, Hexadecimal, Binary…

Random links:Sassafras | Tefnakht | Panionios Athens | Of love and fresh water | Lars Theodor Jonsson | Internet_Assigned_Numbers_Authority