home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Amiga / Workbench / Archivers / base64.lha / base64 / rfc1341.txt < prev    next >
Text File  |  1998-04-26  |  7KB  |  126 lines

  1.  
  2.  The following is an excerpt from RFC 1341 which defines Base64 encoding.
  3.  
  4.  
  5.             Network Working Group               N. Borenstein, Bellcore
  6.             Request for Comments: 1341               N. Freed, Innosoft
  7.                                                               June 1992
  8.                    MIME  (Multipurpose Internet Mail Extensions):
  9.  
  10.                       Mechanisms for Specifying and Describing
  11.                        the Format of Internet Message Bodies
  12.  
  13.                    Excerpt Defining Base64 Encoding
  14.  
  15.  
  16.             5.2  Base64 Content-Transfer-Encoding
  17.  
  18.             The  Base64   Content-Transfer-Encoding   is   designed   to
  19.             represent  arbitrary  sequences  of octets in a form that is
  20.             not humanly readable.  The encoding and decoding  algorithms
  21.             are simple, but the encoded data are consistently only about
  22.             33 percent larger than the unencoded data.  This encoding is
  23.             based on the one used in Privacy Enhanced Mail applications,
  24.             as defined in RFC 1113.   The  base64  encoding  is  adapted
  25.             from  RFC  1113, with one change:  base64 eliminates the "*"
  26.             mechanism for embedded clear text.
  27.  
  28.             A 65-character subset of US-ASCII is used, enabling  6  bits
  29.             to  be  represented per printable character. (The extra 65th
  30.             character, "=", is used  to  signify  a  special  processing
  31.             function.)
  32.  
  33.             NOTE:  This subset has the important  property  that  it  is
  34.             represented   identically   in  all  versions  of  ISO  646,
  35.             including US ASCII, and all characters  in  the  subset  are
  36.             also  represented  identically  in  all  versions of EBCDIC.
  37.             Other popular encodings, such as the encoding  used  by  the
  38.             UUENCODE  utility  and the base85 encoding specified as part
  39.             of Level 2 PostScript, do not share  these  properties,  and
  40.             thus  do  not  fulfill the portability requirements a binary
  41.             transport encoding for mail must meet.
  42.  
  43.             The encoding process represents 24-bit groups of input  bits
  44.             as  output  strings of 4 encoded characters. Proceeding from
  45.             left  to  right,  a  24-bit  input  group   is   formed   by
  46.             concatenating  3  8-bit input groups. These 24 bits are then
  47.             treated as 4 concatenated 6-bit groups,  each  of  which  is
  48.             translated  into a single digit in the base64 alphabet. When
  49.             encoding a bit stream  via  the  base64  encoding,  the  bit
  50.             stream  must  be  presumed  to  be  ordered  with  the most-
  51.             significant-bit first.  That is, the first bit in the stream
  52.             will be the high-order bit in the first byte, and the eighth
  53.             bit will be the low-order bit in the first byte, and so on.
  54.  
  55.             Each 6-bit group is used as an index into  an  array  of  64
  56.             printable  characters. The character referenced by the index
  57.             is placed in the output string. These characters, identified
  58.             in  Table  1,  below,  are  selected so as to be universally
  59.             representable,  and  the  set   excludes   characters   with
  60.             particular  significance to SMTP (e.g., ".", "CR", "LF") and
  61.             to the encapsulation boundaries  defined  in  this  document
  62.             (e.g., "-").
  63.  
  64.                             Table 1: The Base64 Alphabet
  65.  
  66.                Value Encoding  Value  Encoding   Value  Encoding   Value
  67.             Encoding
  68.                    0 A            17 R            34 i            51 z
  69.                    1 B            18 S            35 j            52 0
  70.                    2 C            19 T            36 k            53 1
  71.                    3 D            20 U            37 l            54 2
  72.                    4 E            21 V            38 m            55 3
  73.                    5 F            22 W            39 n            56 4
  74.                    6 G            23 X            40 o            57 5
  75.                    7 H            24 Y            41 p            58 6
  76.                    8 I            25 Z            42 q            59 7
  77.                    9 J            26 a            43 r            60 8
  78.                   10 K            27 b            44 s            61 9
  79.                   11 L            28 c            45 t            62 +
  80.                   12 M            29 d            46 u            63 /
  81.                   13 N            30 e            47 v
  82.                   14 O            31 f            48 w         (pad) =
  83.                   15 P            32 g            49 x
  84.                   16 Q            33 h            50 y
  85.  
  86.             The output stream (encoded bytes)  must  be  represented  in
  87.             lines  of  no more than 76 characters each.  All line breaks
  88.             or other characters not found in Table 1 must be ignored  by
  89.             decoding  software.   In  base64 data, characters other than
  90.             those in  Table  1,  line  breaks,  and  other  white  space
  91.             probably  indicate  a  transmission  error,  about  which  a
  92.             warning  message  or  even  a  message  rejection  might  be
  93.             appropriate under some circumstances.
  94.  
  95.             Special processing is performed if fewer than  24  bits  are
  96.             available  at  the  end  of  the data being encoded.  A full
  97.             encoding quantum is always completed at the end of  a  body.
  98.             When  fewer  than  24  input  bits are available in an input
  99.             group, zero bits  are  added  (on  the  right)  to  form  an
  100.             integral number of 6-bit groups.  Output character positions
  101.             which are not required to represent actual  input  data  are
  102.             set  to  the  character  "=".   Since all base64 input is an
  103.             integral number of octets,  only  the  following  cases  can
  104.             arise:  (1)  the  final  quantum  of  encoding  input  is an
  105.             integral multiple of  24  bits;  here,  the  final  unit  of
  106.             encoded  output will be an integral multiple of 4 characters
  107.             with no "=" padding, (2) the final quantum of encoding input
  108.             is  exactly  8  bits; here, the final unit of encoded output
  109.             will  be  two  characters  followed  by  two   "="   padding
  110.             characters,  or  (3)  the final quantum of encoding input is
  111.             exactly 16 bits; here, the final unit of encoded output will
  112.             be three characters followed by one "=" padding character.
  113.  
  114.             Care must be taken to use the proper octets for line  breaks
  115.             if base64 encoding is applied directly to text material that
  116.             has not been converted to  canonical  form.  In  particular,
  117.             text  line  breaks  should  be converted into CRLF sequences
  118.             prior to base64 encoding. The important  thing  to  note  is
  119.             that this may be done directly by the encoder rather than in
  120.             a prior canonicalization step in some implementations.
  121.  
  122.             NOTE: There is no  need  to  worry  about  quoting  apparent
  123.             encapsulation  boundaries  within  base64-encoded  parts  of
  124.             multipart entities because no hyphen characters are used  in
  125.             the base64 encoding.
  126.