home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / UTILITY / FILE / UUEXE502.ZIP / UUDECODE.DOC next >
Encoding:
Text File  |  1991-11-13  |  12.7 KB  |  278 lines

  1.  
  2. UU-encoding is a way to code a file which may contain any characters into
  3. a standard character set that can be reliably sent over diverse networks.
  4.  
  5.  
  6. THE CHARACTER ENCODING:
  7.  
  8. The basic scheme is to break groups of 3 eight bit characters (24 bits) into
  9. 4 six bit characters and then add 32 (a space) to each six bit character
  10. which maps it into the readily transmittable character.  Another way of
  11. phrasing this is to say that the encoded 6 bit characters are mapped into
  12. the set:
  13.         `!"#$%&'()*+,-./012356789:;<=>?@ABC...XYZ[\]^_
  14. for transmission over communications lines.
  15.  
  16. As some transmission mechanisms compress or remove spaces, spaces are changed
  17. into back-quote characters (a 96).  (A better scheme might be to use a bias
  18. of 33 so the space is not created, but this is not done.)
  19.  
  20. Another newer less popular encoding method, called XX-encoding uses the set:
  21.         +-01..89ABC...XYZabc...xyz
  22.  
  23. In my opinion, XX-encoding is superior to UU-encoding because it uses more
  24. "normal" characters that are less likely to get corrupted.  In fact several
  25. of the special characters in the UU set do not get thru an EBCDIC to ASCII
  26. translation correctly.  Conversely, an advantage of the UU set is that it does
  27. not use lower case characters.  Now-a-days both upper and lower case are sent
  28. with no problems; maybe in the communications dark ages, there was a problem
  29. with lower case.
  30.  
  31. This "UU" encode/decode pair can handle either XX or UU encoding.  The encode
  32. program defaults to creating a UU encoded file; but can be run with a "-x"
  33. option to create an XX encoding.
  34.  
  35. The decode program defaults to autodetect.  However the program can get
  36. confused by comment lines preceeding the actual encoded data.  The decode
  37. mode can be forced to UU or XX with the "-u" or "-x" parameter.
  38.  
  39. Another option is for the actual map table to be inserted at the front of the
  40. file.  The format for this is discussed later.  The table parameters are
  41. detected and used by this decode program.  (A table will override the "-x" or
  42. "-u" parameters.)  The encode program can be run with a "-t" option which
  43. tells it to put the table into the encoded file.
  44.  
  45. A third encode mapping is the one used by Brad Templeton's ABE program.  This
  46. is not handled by these programs as the check and control information
  47. surrounding the actual encoded data is in a different form.
  48.  
  49. From a theoritical view, this encoding is breaking down 24 bits modulo 64.  Note
  50. that 64**3 is = 2**24.  The result is 24 bits in for 32 bits out, a 33% size
  51. increase.  Note that 85**5 > 2**32.  Also note that there are 94 transmittable
  52. ASCII characters (from 0x21 thru 0x7e).  Thus modulo 85 encoding (the atob
  53. encoder) transforms 32 bits to 5 ASCII chars or 40 bits for a 25% size increase.
  54.  
  55. The trade off in the module 85 encoding is that many communications systems do
  56. not reliably transmit 85 ASCII characters.  The tidla, carrot, brackets, and
  57. sometimes upper or lower case frequently get corrupted.
  58.  
  59. COMPOSING A LINE OF ENCODED CHARACTERS:
  60.  
  61. A small number of eight bit characters are encoded into a single line and a
  62. count is put at the start of the line.  (Most lines in an encoded file have 45
  63. encoded characters.  When you look at a UU-encoded file note that most lines
  64. start with the letter "M".  "M" is decimal 77 which, minus the 32 bias, is 45.)
  65.  
  66. This encode program puts a check character at the end of each line.  The check
  67. is the sum of all the encoded characters, before adding the mapping, modulo 64.
  68.  
  69. Note: Horton 9/1/87 UUENCODE has a bug in the line check algorithm; it uses the
  70. sum of the original, not the encoded characters.  This decode program accepts
  71. either form of line check character.
  72.  
  73. In previous versions (4.13 and lower) the line check characters was generated by
  74. default by this encode program and was supressed with the "-L" option.  One
  75. reason to supress them is if they will be decoded by one of the old Horton
  76. decoders.  Most decoders either accept this form of check or simply stop looking
  77. after the line length is exhausted.  My feelings are mixed about the line
  78. checksums because errors of this type essentially never occur.
  79.  
  80. However with modern, error-free communications systems and with the CRC checks
  81. on the entire file (see below) I have made the default for uuencoding to have NO
  82. line level check characters effective version 4.21.  The "-L" option on uuencode
  83. turns on generation of line checksums.  If you have a really bad communications
  84. system and you want to isolate a problem, turn them on.
  85.  
  86. Uudecode automatically checks for the presense line checksums, so the default
  87. for uudecode is to leave line level checks on; if there are some problems the
  88. "-L" option for uudecode turns them off.  Sometimes there is junk at the end of
  89. the line which causes spurious line checksum errors.
  90.  
  91. I have encountered various other ways that encoders end lines.  One encoder
  92. put a "M" at both the start and end of the line.  Another used a line count
  93. character.  This decode program checks all of these.  I would not be surprised
  94. if some encoder out there ends lines with astrological symbols.  If you
  95. encounter some other wierd form of encoded file, let me know.
  96.  
  97.  
  98. PACKAGING THE LINES INTO FILES:
  99.  
  100. The lines of encoded data can be preceded by comments and by network addressing
  101. information.  The encoded data is directly preceded by a line containing:
  102.  
  103.              begin <file-mode> <file-name>
  104.  
  105. This line is created by the encoding program.  The decode program scans the
  106. file looking for "begin" in column 1.
  107.  
  108. The final end of encoded data is an encoded line with zero encoded characters
  109. (a back-quote), followed by a line containing "end".
  110.  
  111. For integrity checking, various encode programs insert checksums for the
  112. entire file.  This decode tries to check for all known types of file checksums.
  113. This is discussed in more detail later.
  114.  
  115. This encode program puts a header line, containing the section number and
  116. file name, in front of every section:
  117.  
  118.          "section <number> of uuencode of file <file name>"
  119.  
  120. At the end of a section the encode program inserts a line containing checksum
  121. and file size information.  This can be suppressed with the "-c" option.
  122.  
  123. The transmissions on comp.binaries.ibm.pc contain two different types of section
  124. number/file-name lines.  The first is the "Archive-name line"; the other is the
  125. "part line".
  126.  
  127. The format of the Archive-name line is:
  128.         "Archive-name: <name>/part<number>"
  129. for example:
  130.         Archive-name: diskutl/part02
  131.  
  132. The format of the part line is:
  133.         <name> part<number>/<max-number>
  134. for example:
  135.         diskutl part02/03
  136.  
  137. This program checks for consistency of these names and numbers as of release
  138. 5.0.
  139.  
  140. All the "integrity fields" (the checksum, the line check, and the section
  141. header line) are inserted in a way that they will be ignored by other UUDECODE
  142. programs that cannot handle them.  This decode program does not require any of
  143. these fields; if not present, integrity checking is not done.  This program
  144. pair is 100% downward compatible!
  145.  
  146.  
  147. SPLITING UP LONG FILES:
  148.  
  149. Long files are broken into several sections before transmission.  This is
  150. done because very large files are cumbersome to handle and because some
  151. networks require files to be less than 64K bytes.
  152.  
  153. This encode program automatically breaks large encoded files into sections.
  154. This split is controlled by several options.  First the "-s" option tells
  155. encode not to split the file.  The "-s nnn" option tells encode to split the
  156. file into hunks of "nnn" lines.  The default is 950 lines which is about 59k.
  157. Sometimes extensive comments are put into the first file; thus it may be
  158. necessary for the first file to contain fewer encoded lines.  The "-h nnn"
  159. option tells encode to leave room for "nnn" additional lines in the first file.
  160.  
  161. If the data file being encoded is called FOO.ZIP, then the encode program
  162. names the encoded files FOO1.UUE, FOO2.UUE, etc.
  163.  
  164. The decode program searches for the various sections, scans over preliminary
  165. comments and decodes all as if they were one big file.  Decode is passed the
  166. base file name "FOO".
  167.  
  168. Decode can (but rarely does) get confused and thinks header lines are encoded
  169. data.  If so, edit the file and try again.  This has only happened once to me
  170. and I have decoded a lot of files.
  171.  
  172. When decode encounters a premature end-of-file or some data which is not
  173. decodable, it assumes the end of a file section.  decode is conservative when
  174. it encounters data it cannot decode.
  175.  
  176. Usually this undecodable data is valid "trailer" data put at the end of file
  177. for data transmission purposes.  However the file may be bad.  So decode
  178. continues to scan the file, if decode then encounters a line which is decodable
  179. it assumes the file is bad.  Or if there are more than 30 lines remaining in
  180. the file, decode assumes the file is bad.
  181.  
  182. When decode encounters a valid end of file section it must get the next file
  183. in sequence.  If the file name ends with a number, decode tries the next file
  184. name in numeric sequence.  Otherwise decode asks for a file name.  If this
  185. file does not contain decodable data, decode asks for another file to try.
  186.  
  187. The "SECTION" line inserted by the encode program is used for validity checking
  188. only.  If not present, decode will accept any file containing encoded lines.
  189.  
  190.  
  191. OTHER FILE FORMS:
  192.  
  193. Sometimes files come across in shell archives that automatically check
  194. sequencing and call uudecode for you on the UNIX systems.  If you prefer to
  195. download the raw files to MS-DOS, this decode program will filter thru simple
  196. shell scripts and decode the data automatically.
  197.  
  198. There is one more rarely used feature of ENCODE: many input files can be
  199. encoded into one large encode file.  (I have never seen this used.)  The end
  200. of an input file is a zero length encoded line, followed by another "begin"
  201. line instead of by an "end" line.  This decode program will decode this sort of
  202. file; but the encode will only handle a single input file.
  203.  
  204.  
  205. FILE LEVEL CHECKSUMS:
  206.  
  207. There are three types of file checksums found in encoded files:
  208.  
  209.        UUENCODE 2.14 and below inserted lines that gave the section
  210.        size and the original input file size.  This is supplanted
  211.        by a better technique in 3.07; but 3.07 UUDECODE still checks
  212.        and validates the old form
  213.  
  214.        UUENCODE 3.07 and Rahul Dhesi''s encode scripts compute a Unix
  215.        "sum -r" on the encoded sections and on the original input file.
  216.        A difference is that UUENCODE 3.07 puts the expected "sum -r"
  217.        and size at the end of a file while Rahul''s scripts put them at
  218.        begining.  This UUDECODE analyzes either.
  219.  
  220.        The third form of checksum is a full 32 bit CRC that Rahul''s script
  221.        inserts.  My code does not handle this.  Rahul has written the
  222.        BRIK program to check them.  If there is a "sum -r" failure, BRIK
  223.        analysis should be considered.
  224.  
  225. Also Unisys Unix platforms put a line containing just the original file size at
  226. the end of the encoded file.  My code checks this.
  227.  
  228.  
  229. TABLE LINES:
  230.  
  231. Some encoded files but the mapping used at the front of the encoded file,
  232. just in front of the "begin" line.  The format for this is:
  233.  
  234.                    table
  235.                    first 32 characters
  236.                    second 32 characters
  237.  
  238. All this starts in column 1.
  239.  
  240. If decode encounters a table specification, it uses it and overrides any
  241. command line parameters.  Encode will create the table lines if run with
  242. the "-t" parameter.
  243.  
  244.  
  245. COMPLETION CODES:
  246.  
  247. On successful completion, UUDECODE sets ERRORLEVEL to 0.  If there are any
  248. problems, ERRORLEVEL is set to non-zero.
  249.  
  250. Most of the options to UUDECODE are obvious.  However, the "-e" option needs
  251. more explanation.  The purpose of "-e" is to automatically run an un-archiver
  252. (like ZOO or PKUNPAK) when UUDECODE successfully completes.  If the "-e"
  253. option is given, UUDECODE calls BAT file UNARCUUE on successful completion
  254. UNARCUUE is passed two parameters:
  255.  
  256.                 the filename decoded (with no extension)
  257.                 the file extension.
  258.  
  259. Normally the file extension tells which un-archiver to call.  The UNARCUUE
  260. BAT file, can test these parameters and call the necessary un-archiver.
  261.  
  262.  
  263. This works well for me.  On UNIX I find a program I want in three sections:
  264.               PRG1, PRG2, PRG3.
  265. I copy the three files down to my PC as PRG1.UUE, PRG2.UUE, and PRG3.UUE.  I
  266. then just enter UUDECODE PRG and the thing decodes.
  267.  
  268.  
  269. Done privately and not for profit (freeware).  Suggestions appreciated.
  270. The programs are written in Turbo Pascal 5.5 with about 5% TASM for speed.
  271. The source is not public domain.  I would entertain consulting contracts
  272. for porting to other hardware platforms.
  273.  
  274.  
  275. Richard Marks
  276. 931 Sulgrave Lane
  277. Bryn Mawr, PA 19010
  278.