home *** CD-ROM | disk | FTP | other *** search
/ The First Hungarian Family / The_First_Hungarian_Family_CD-ROM.bin / internet / coddecod / uuexecod / uutech.txt < prev   
Text File  |  1995-06-01  |  16KB  |  373 lines

  1. This file contains a write-up of the more technical aspects of
  2. uuencoding and uudecoding.  First read the file UUSER.TXT, then read
  3. this for more details.
  4.  
  5. Documentation for UUENCODE/DECODE 95 (v40)
  6.  
  7. UU-encoding is a way to code a file which may contain any characters
  8. into a standard character set that can be reliably sent over diverse
  9. networks.
  10.  
  11.  
  12. THE CHARACTER ENCODING:
  13.  
  14. The basic scheme is to break groups of 3 eight bit characters (24 bits)
  15. into 4 six bit characters and then add 32 (a space) to each six bit
  16. character which maps it into a readily transmittable character.  Another
  17. way of phrasing this is to say that the encoded 6 bit characters are
  18. mapped into the set:
  19.         `!"#$%&'()*+,-./012356789:;<=>?@ABC...XYZ[\]^_
  20. for transmission over communications lines.
  21.  
  22. As some transmission mechanisms compress or remove spaces, spaces are
  23. changed into back-quote characters (a 96).  (A better scheme might be to
  24. use a bias of 33 so the space is not created, but this is not done.)
  25.  
  26. A newer, less popular, encoding method, called XX-encoding uses the set:
  27.         +-01..89ABC...XYZabc...xyz
  28.  
  29. In my opinion, XX-encoding is superior to UU-encoding because it uses
  30. more "normal" characters that are less likely to get corrupted.  In fact
  31. several of the special characters in the UU set do not get through an
  32. EBCDIC to ASCII translation correctly.  Conversely, an advantage of the
  33. UU set is that it does not use lower case characters.  Now-a-days both
  34. upper and lower case are sent with no problems; maybe in the
  35. communications dark ages, there was a problem with lower case.
  36.  
  37. This "UU" encode/decode pair can handle either XX or UU encoding.  The
  38. encode program defaults to creating a UU encoded file; but can be run
  39. with a "-x" option to create an XX encoding.
  40.  
  41. The decode program defaults to autodetect.  However the program can get
  42. confused by comment lines preceding the actual encoded data.  The decode
  43. mode can be forced to UU or XX with the "-u" or "-x" parameter.
  44.  
  45. Another option is for the character mapping table to be inserted at the
  46. front of the file.  The format for this is discussed later.  The table
  47. parameters are detected and used by this decode program.  (A table will
  48. override the "-x" or "-u" parameters.) The encode program can be run
  49. with a "-t" option which tells it to put the table into the encoded
  50. file.
  51.  
  52. A third encode mapping is the one used by Brad Templeton's ABE program.
  53. This is not handled by these programs as the check and control
  54. information surrounding the actual encoded data is in a different form.
  55.  
  56. From a theoretical view, this encoding is breaking down 24 bits modulo
  57. 64.  Note that 64**3 is = 2**24.  The result is 24 bits in for 32 bits
  58. out, a 33% size increase.  Note that 85**5 > 2**32.  Also note that
  59. there are 94 transmittable ASCII characters (from 0x21 through 0x7e).
  60. Thus modulo 85 encoding (the atob encoder) transforms 32 bits to 5 ASCII
  61. chars or 40 bits for a 25% size increase.
  62.  
  63. The trade off in the modulo 85 encoding is that many communications
  64. systems do not reliably transmit 85 ASCII characters.  The tilde, carat,
  65. brackets, and sometimes upper or lower case, may get corrupted.
  66.  
  67. There are three other popular encoding techniques.  One is BinHex used on
  68. Apple Computers.  The current version is BinHex 4.0.  BinHex uses
  69. another mapping into 64 characters.  The first encoded line in a BinHex
  70. file is an encoded structure that contains the file name, size,
  71. checksum, date and time The remaining lines are encoded data.
  72.  
  73. Another technique that I have seen is BinMail used on Unisys A-series.
  74.  
  75. The most recent mechanism is incorporated into MIME and is called
  76. Base64 encoding.  I support this as a $10 shareware option.  It uses
  77. another character mapping of 64 characters with no checksums and no
  78. special "end" indicator.
  79.  
  80.  
  81. COMPOSING A LINE OF ENCODED CHARACTERS:
  82.  
  83. A small number of eight bit characters are encoded into a single line
  84. and a count is put at the start of the line.  (Most lines in an encoded
  85. file have 45 encoded characters.  When you look at a UU-encoded file
  86. note that most lines start with the letter "M".  "M" is decimal 77
  87. which, minus the 32 bias, is 45.)
  88.  
  89. BinHex does not use this count character, every encoded line contains 64
  90. characters.  Except the last is limited by the size obtained from the
  91. first line.
  92.  
  93. This encode program optionally puts a check character at the end of each
  94. line.  The check is the sum of all the encoded characters, before adding
  95. the mapping, modulo 64.
  96.  
  97. Note: Horton 9/1/87 UUENCODE has a bug in the line check algorithm; it
  98. uses the sum of the original, not the encoded characters.  This decode
  99. program accepts either form of line check character.
  100.  
  101. In previous versions (4.13 and lower) the line check characters was
  102. generated by default by this encode program and was suppressed with the
  103. "-L" option.  One reason to suppress them is if they will be decoded by
  104. one of the old Horton decoders.  Most decoders either accept this form
  105. of check or simply stop looking after the line length is exhausted.  My
  106. feelings are mixed about the line checksums because errors of this type
  107. essentially never occur.
  108.  
  109. Given modern, error-free communications systems and the CRC checks on
  110. the entire file (see below) I have made the default for uuencoding to
  111. have NO line level check characters effective version 4.21.  The "-L"
  112. option on uuencode turns on generation of line checksums.  If you have a
  113. really bad communications system and you want to isolate a problem, turn
  114. them on.
  115.  
  116. Uudecode automatically checks for the presence of line checksums; so the
  117. default for uudecode is to leave line level checks on; if there are some
  118. problems the "-L" option for uudecode turns them off.  Sometimes there
  119. is junk at the end of the line which causes spurious line checksum
  120. errors.
  121.  
  122. I have encountered various other ways that encoders end lines.  One
  123. encoder put an "M" at both the start and end of the line.  Another used
  124. a line count character.  This decode program checks all of these.  I
  125. would not be surprised if some encoder out there ends lines with
  126. sequential astrological symbols.  If you encounter some other weird form
  127. of encoded file, let me know.  (The -L option turns line level checking
  128. off.)
  129.  
  130.  
  131. PACKAGING THE LINES INTO FILES:
  132.  
  133. The lines of encoded data can be preceded by comments and by network
  134. addressing information.  The encoded data is directly preceded by a line
  135. containing:
  136.  
  137.              begin <file-mode> <file-name>
  138.  
  139. This line is created by the encoding program.  The decode program scans
  140. the file looking for "begin" in column 1.  The following line is the
  141. encoded data.
  142.  
  143. Some encoders put file time and date information on the begin line:
  144.  
  145.              begin <file-mode> <file-name> <date> <time>
  146.  
  147. My UUdecoder will accept this form of begin line, but does not use the
  148. time and date information.
  149.  
  150. The final end of encoded data is an encoded line with zero encoded
  151. characters (a back-quote), followed by a line containing "end".
  152.  
  153. For integrity checking, some encode programs insert checksums for the
  154. entire file.  This decode tries to check for all known types of file
  155. checksums.  This is discussed in more detail below.
  156.  
  157. This encode program puts a header line, containing the section number
  158. and file name, in front of every section:
  159.  
  160.          "section <number> of uuencode of file <file name>"
  161.  
  162. At the end of a section the encode program inserts a line containing
  163. checksum and file size information.  This can be suppressed with the
  164. "-c" option.
  165.  
  166. Other encoders use a variety of section lines:
  167.  
  168.         The format of the Archive-name line is:
  169.                 "Archive-name: <name>/part<number>"
  170.         for example:
  171.                 Archive-name: diskutl/part02
  172.  
  173.         The format of the part line is:
  174.                 <name> part<number>/<max-number>
  175.         for example:
  176.                 diskutl part02/03
  177.  
  178.         WinCode uses:
  179.                 [ section: 1/2 file: diskutl.exe . . . .
  180.  
  181.         enuu uses:
  182.                 section 001/002  diskutl.exe  . . . .
  183.  
  184. This program checks for consistency of these names and numbers as of
  185. release 5.0.  The problem is distinguishing random text from valid
  186. lines.
  187.  
  188. For each line that uudecode thinks is a "section" line, tests are made
  189. to validate the current section number, the maximum section number and
  190. the file name.  The program is conservative and may sometimes
  191. erroneously give an "invalid section line" type of error.  Inspect the
  192. file; if uudecode made a mistake, edit or delete the indicated line; and
  193. continue.  If the problem appears to be a uudecode problem, not just
  194. some random comment lines that caused a one time problem, please contact
  195. me.
  196.  
  197. All the "integrity fields" (the checksum, the line check, and the
  198. section header line) are inserted in a way that they will be ignored by
  199. other UUDECODE programs that cannot handle them.  This decode program
  200. does not require any of these fields; if not present, integrity checking
  201. is not done.  This program pair is 100% downward compatible!
  202.  
  203.  
  204. FILE NAMES:
  205.  
  206. See UUSER.TXT for a discussion of file naming conventions.
  207.  
  208.  
  209.  
  210. DECODE and VALID LINES:
  211.  
  212. The below information is to help you solve infrequent problems when
  213. decoding files.  Normally you do not have to be concerned with any of
  214. this stuff.
  215.  
  216. UUdecode sometimes get confused and thinks header lines are encoded
  217. data.  Sometimes this is because the separator line between sections
  218. (the "cut" line) is indistinguishable from valid decodable data.  (An
  219. example is the line "---" used as a cut line on several DOS BBS
  220. systems.) You can tell UUdecode that a specific line is a cut line and
  221. not a decodable line with the -Z option:
  222.  
  223.     uudecode -Z "---" myfile
  224.  
  225. Other times there is not a cut line between file sections or there is
  226. some other problem with the file.  If so, edit the file and try again.
  227.  
  228. When decode encounters a premature end-of-file or some data which is not
  229. decodable, it assumes the end of a file section.  Decode is conservative
  230. when it encounters data it cannot decode (better an error than a bad
  231. file).
  232.  
  233. Usually this undecodable data is valid "trailer" data put at the end of
  234. file for data transmission purposes.  However the file may be bad.  So
  235. decode continues to scan the file, if decode then encounters a line
  236. which is decodable it assumes the file is bad.
  237.  
  238. When decode encounters a valid end of file section it must get the next
  239. file in sequence.  If the file name ends with a number, decode tries the
  240. next file name in numeric sequence.  Otherwise decode asks for a file
  241. name.  If this file does not contain decodable data, decode asks for
  242. another file to try.
  243.  
  244. If multiple sections are saved in a single file, each section must have
  245. some type of section line for validation.  Decode builds a table of
  246. section information so it can go back and reread if sections are not
  247. saved in order.
  248.  
  249. The "SECTION" line inserted by the UUENCODE program is used for validity
  250. checking only.  If not present, decode will accept any file containing
  251. encoded lines.
  252.  
  253.  
  254. OTHER FILE FORMS:
  255.  
  256. Sometimes files are wrapped in shell archives that automatically check
  257. sequencing and call uudecode for you on Unix systems.  If you prefer to
  258. download the raw files to MS-DOS, uudecode 5.33 will filter simple shell
  259. scripts, that use the Unix 'sed' command, and decode the data
  260. automatically.
  261.  
  262. There is one more rarely used feature of ENCODE: many input files can be
  263. encoded into one large encode file.  (I have never seen this used.) The
  264. end of an input file is a zero length encoded line, followed by another
  265. "begin" line instead of by an "end" line.  This decode program will
  266. decode this sort of file; but the encode will only handle a single input
  267. file.
  268.  
  269.  
  270. FILE LEVEL CHECKSUMS:
  271.  
  272. There are three types of file checksums found in encoded files:
  273.  
  274.        UUENCODE 2.14 and below inserted lines that gave the section
  275.        size and the original input file size.  This is supplanted
  276.        by a better technique in 3.07; but 3.07 UUDECODE still checks
  277.        and validates the old form
  278.  
  279.        UUENCODE 3.07 and Rahul Dhesi's encode scripts compute a Unix
  280.        "sum -r" on the encoded sections and on the original input file.
  281.        A difference is that UUENCODE 3.07 puts the expected "sum -r"
  282.        and size at the end of a file while Rahul''s scripts put them at
  283.        beginning.  This UUDECODE analyzes either.
  284.  
  285.        The third form of checksum is a full 32 bit CRC that Rahul's
  286.        script inserts.  My code does not handle this.  Rahul has written
  287.        the BRIK program to check them.  If there is a "sum -r" failure,
  288.        BRIK analysis should be considered.
  289.  
  290. Several encoders put in a line containing just the original file size.
  291. My uudecode checks these.
  292.  
  293.  
  294. TABLE LINES:
  295.  
  296. Some encoded files but the mapping used at the front of the encoded
  297. file, just in front of the "begin" line.  The format for this is:
  298.  
  299.                    table
  300.                    first 32 characters
  301.                    second 32 characters
  302.  
  303. All this starts in column 1.
  304.  
  305. If decode encounters a table specification, it uses it and overrides any
  306. command line parameters.  Encode will create the table lines if run with
  307. the "-t" parameter.
  308.  
  309.  
  310. COMPLETION CODES:
  311.  
  312. On successful completion, UUDECODE sets ERRORLEVEL to 0.  If there are
  313. any problems, ERRORLEVEL is set to non-zero.
  314.  
  315. The purpose of "-e" is to automatically run an un-archiver (like PKZIP
  316. or ARJ) when UUDECODE successfully completes.  If the "-e" option is
  317. given, UUDECODE calls BAT file UNARCUUE on successful completion;
  318. UNARCUUE is passed five parameters:
  319.  
  320.                 the filename decoded (with path but no extension),
  321.                 the file extension,
  322.                 the input file name  (with path but no extension),
  323.                 the input file extension that is used,
  324.                 the number of sections.
  325.  
  326. Normally the file extension tells which un-archiver to call.  The
  327. UNARCUUE BAT file, can test these parameters and call the necessary
  328. un-archiver.  If UNARCUUE is called, the return code from UUDECODE is
  329. the return code passed back from UNARCUUE.  Note: one user had a problem
  330. in that the routines called by UNARCUUE set the errorlevel to 1 which
  331. was passed back to be the return code from UUDECODE.
  332.  
  333. The "-E" (upper case) option is like "-e" but you can supplythe name of
  334. the file to execute.
  335.  
  336. If you are running an automated system, the -y or -n options which force
  337. a "Y" or "N" response to messges, may be helpful.
  338.  
  339. BUGS and PROBLEMS:
  340.  
  341. I try to make this program as good as possible.  If you find a problem,
  342. please send me a diskette.  You can mail a 3 1/2" diskette in a regular
  343. envelope, with no special protection, with a single stamp.
  344.  
  345.  
  346. CONCLUSION:
  347.  
  348. This works well for me.  On UNIX I find a program I want in 3 sections:
  349.               PRG1, PRG2, PRG3.
  350. I copy the three files down to my PC as PRG1.UUE, PRG2.UUE, and PRG3.UUE.  I
  351. then just enter UUDECODE PRG and the thing decodes.
  352.  
  353.  
  354. Done privately and not for profit (freeware).  Suggestions appreciated.
  355. The programs are written in Turbo Pascal 5.5 with about 5% TASM for speed.
  356. The source is not public domain.  If included in your for profit product,
  357. please contact me.
  358.  
  359.  
  360. Richard Marks (KE3TL)
  361. 931 Sulgrave Lane
  362. Bryn Mawr, PA 19010
  363.  
  364. Copyright (c) Richard E. Marks, Bryn Mawr, PA, 1992, 1993, 1994, 1995
  365.  
  366. Also Copyright program name of
  367.      UUENCODE 95, UUDECODE 95, UUCODE 95, UUWIN 95,
  368.      UUENCODE 96, UUDECODE 96, UUCODE 96, UUWIN 96,
  369.      UUENCODE 97, UUDECODE 97, UUCODE 97, UUWIN 97,
  370.      UUENCODE 98, UUDECODE 98, UUCODE 98, UUWIN 98,
  371.      UUENCODE 99, UUDECODE 99, UUCODE 99, UUWIN 99
  372. Copyright (c) by Richard E. Marks, Bryn Mawr, PA 1995
  373.