home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / misc / 4234 < prev    next >
Encoding:
Text File  |  1992-11-07  |  15.3 KB  |  349 lines

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