[comp.sys.amiga] UUencode for the simple-minded...

noel@uokmax.UUCP (Bamf) (05/01/89)

This is in response to the multitude of 'has anyone ported uudecode to
such-and-such computer' questions that have come across in the past few
months...

The following is a simple 'how-do-it-do-it' for uuencode.  For those
of you that already knew this, I apologize for the waste of width,
but I have never actually seen this posted anywhere.  (yes, I know
it's trivial, but if it were so trivial, howcome so many people are
looking for ports...)

-----------------------
UUENCODE: How it works.

Basically, UUencode takes 3 8-bit characters, and makes 4 6-bit
characters out of it.   (the easiest way being by shifting and masking
unwanted bits.)   

  Character 1      Character 2     Character 3
_________________________________________________
|               |               |               |
v               v               v               v
 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 
^           ^           ^           ^           ^
|___________|___________|___________|___________|
  Byte 1       Byte 2        Byte 3       Byte 4

with something like this:

	/* p[2] = 3 characters to be encoded */

	i1 = p[0] >> 2;
	i2 = (p[0] << 4) & 060 | (p[1] >> 4) & 017;
	i3 = (p[1] << 2) & 074 | (p[2] >> 6) & 03;
	i4 = p[2] & 077;

Each resulting 6-bit code is of course stored in an 8-bit byte, so the
top two bits are masked out, and the value of ' ' (space) is added to
the total.          /* ((c & 077) + ' ') */

This guarantees a final value between 32 and 96, (the printable
characters of (space) and ` (backquote)


Yes, this is all as simple as it sounds, with a few little additions:
UUencode reads in a buffer of 45 characters, masks and encodes the
number of bytes read, and starts the line with that number.   (hence,
all the M's that are found as the first character of a line in
uuencoded files.)   After 45 bytes, a newline is appended, and it reads
in the next 45 characters.

So, now you can easily port all of this to your favorite (however
bloody obscure) computer.   Have fun, and please direct all flames to
richard@gryphon.COM, he needs the grief.

-- Bamf

-- 
 NEVER date a music major.  At least not one that's named her clarinet "Thor" 
----You want it should sing too?------|  noel@uokmax | csm9a!bgphp1!ngorelic
<Dis-Claimer, Dat-Claimer, to look at |        uokmax!tavern!anyone
 'em, you'd never know the diff...>   | "Beam me up Scotty, we're outta beer"