[comp.sys.cbm] UUENCODE / UUDECODE for C-64

davef@brspyr1.BRS.Com (Dave Fiske) (12/23/89)

A short while ago, someone was looking for some UUENCODE/UUDECODE stuff
that had been posted on the net ages ago.  I thought I had saved it,
but couldn't locate it, until today, when I found two compressed files
in my Humor subdirectory.  Why I stored them there, I don't know, but
at least I found them.

There is a UUENCODE program in BASIC, and it is pretty easy to follow.

The UUDECODE/UUENCODE program is, unfortunately, uuencoded.  Thus,
you have to have a way to uudecode it before you can use it. 
This sounds insane, but actually, if you can get the file to a PC or
mini-computer where you already have uudecode, you can transfer it in
binary fashion to your C-64, and you would then have a working version.

Also, I should point out that I have never tried either of these.  I
saved the BASIC program, just because it was an easy way to see how
UUENCODE works, and I saved the uuencoded file with the idea that
someday I might make the effort to actually transfer it onto my 64.
(I still haven't.)

Anyway, here are the two files.

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
FILE 1
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *


From bowen@sunybcs.UUCP Sat Jan 30 22:47:25 1988
Path: brspyr1!steinmetz!ge-dab!codas!mtune!rutgers!rochester!rocksanne!sunybcs!bowen
From: bowen@sunybcs (Devon E Bowen)
Newsgroups: comp.sys.cbm
Subject: UUENCODE listing
Message-ID: <8190@sunybcs.UUCP>
Date: 31 Jan 88 03:47:25 GMT
Sender: nobody@sunybcs.UUCP
Reply-To: bowen@sunybcs.UUCP (Devon E Bowen)
Organization: SUNY/Buffalo Computer Science
Lines: 133


Ok, I guess it's a little longer than 20 lines (it only seemed that long
while I was writing it). But here's the BASIC program I have to uuencode
C64/128 programs. I'm posting it due to its short length and at the request
of a number of people who have contacted me. This code is *far* from
perfect. It is very slow (just be patient with it). Some suggestions as
to how to improve it are:

1) Change the code to read a data file block by block rather than character
   by character. Of course, if you're going to do this, you might as well
   write it in assembly language.

2) Save up an entire line for the output file before writing it. Again,
   don't do it character by character.

3) Compile it!

4) Write it in assembly!!

I guess I should give a little description of how uuencoding works so that
some fun loving programmer can write the uudecode for this (or so that someone
can improve this one). Uuencoding basically consists of taking 3 bytes at a
time and expanding them into 4 printable ascii characters. Since each byte
contains 8 bits there is a total of 24 bits to translate. Since 24 divided
by 4 equals 6, it makes sense to break up the bytes into 6 bit chunks. The
bytes are broken up as:

              b b b b b b b b  b b b b b b b b  b b b b b b b b
                         ^            ^            ^
                char 1       char 2       char 3       char 4

where a "b" represents a bit in each of the 3 bytes. If all the bits for
each character are 0, the character is translated into the ' character.
Otherwise, the character number is added to 32 (decimal) to get a printable
ascii character. These four bytes are then printed to the file. As a matter
of convention, this is done 15 times per line making 45 data bytes encoded
into one 61 character line (The first character of the line is just a
character that tells how many data bytes are in the line. This is usually
an M since there are usually 15 bytes per line and chr$(15 + 32) is an
M). Also given in the file is a header line that contains the word 'begin',
the name of the binary file and the mode it will become (this will usually
be 600 - readable and writable by the user). There is also a final line
with a ' on it signifying a line with 0 bytes and an 'end' line. Well,
that's all there is to it...

If anyone improves this in any way, I'd be interested in the code. Also,
if someone gets a uudecode written, please send me the code. If anyone has
any questions or comments, just send me mail. Enjoy...

				    Devon Bowen (KA2NRC)
				    University of Buffalo

*********************************************************
uucp:	   ..!{ames,boulder,decvax,rutgers}!sunybcs!bowen
Internet:  bowen@cs.Buffalo.EDU
BITNET:    bowen@sunybcs.BITNET
*********************************************************


100 REM  UUECODE BY DEVON BOWEN FOR THE COMMODORE 64/128
110 REM  MUCH WORK IS NEEDED. FEEL FREE TO HACK AND DISTRIBUTE.
120 REM
130 PRINT:PRINT"C64 - UUENCODE"
140 PRINT"--------------":PRINT
150 INPUT"ENCODE WHAT FILE"; F$
160 IF F$="" THEN GOTO 150
170 PRINT"IS IT <S>EQ OR <P>RG? ";
180 GET FT$:IF FT$="" THEN GOTO 180
190 PRINT FT$:IF FT$<>"S" AND FT$<>"P" THEN GOTO 170
200 PRINT
210 INPUT"WRITE IT TO WHAT FILE"; O$
220 IF O$="" THEN GOTO 210
230 PRINT"IS IT <S>EQ OR <P>RG? ";
240 GET OT$:IF OT$="" THEN GOTO 240
250 PRINT OT$:IF OT$<>"S" AND OT$<>"P" THEN GOTO 230
260 PRINT
270 INPUT"WHAT IS THE UNIX NAME"; D$
280 IF D$="" THEN GOTO 270
290 INPUT"WHAT IS THE FILE MODE"; M$
300 IF M$="" THEN GOTO 290
310 DIM BF(50):SU=0
320 OPEN 2,8,2,F$+","+FT$+",R"
330 OPEN 3,8,3,O$+","+OT$+",W"
340 FOR I = 1 TO LEN(D$)
350 E$=E$+CHR$(ASC(MID$(D$,I,1))+32)
360 NEXT
370 PRINT#3,CHR$(98)+CHR$(101)+CHR$(103)+CHR$(105)+CHR$(110);
380 PRINT#3," "+M$+" "+E$+CHR$(13);
390 GOSUB 610
400 C1 = P1 AND 63
410 IF C1 <> 0 THEN C1 = C1 + 32:GOTO 430
420 C1 = 96
430 PRINT#3,CHR$(C1);
440 CO = 1
450 IF CO > P1 THEN 550
460 C(1) = INT(BF(CO)/4)
470 C(2) = INT(BF(CO+1)/16) AND 15
480 C(2) = C(2) OR (INT(BF(CO)*16) AND 48)
490 C(3) = INT(BF(CO+2)/64) AND 3
500 C(3) = C(3) OR (INT(BF(CO+1)*4) AND 60)
510 C(4) = BF(CO+2) AND 63
520 GOSUB 740
530 CO = CO + 3
540 GOTO 450
550 PRINT#3,CHR$(13);
560 IF P1 <> 0 THEN 390
570 PRINT#3,CHR$(101)+CHR$(110)+CHR$(100)+CHR$(13);
580 CLOSE 3
590 CLOSE 2
600 END
610 REM
620 REM   THIS ROUTINE READS DATA FROM THE FILE IN 45 BYTE BLOCKS
630 REM
640 P1 = 0
650 IF SU <> 0 THEN RETURN
660 GET#2,C$
670 SU = ST
680 P1 = P1 + 1
690 IF C$="" THEN BF(P1)=0:GOTO 710
700 BF(P1) = ASC(C$)
710 IF P1 = 45 THEN RETURN
720 GOTO 650
730 REM
740 REM   THIS ROUTINE PRINTS THE CHARACTERS IN THE C ARRAY AFTER
750 REM   RUNNING THEM THROUGH A SIMPLE FORMULA
760 REM
770 FOR I = 1 TO 4
780 C(I) = C(I) AND 63
790 IF C(I) <> 0 THEN C(I) = C(I) + 32:GOTO 810
800 C(I) = 96
810 PRINT#3,CHR$(C(I));
820 NEXT
830 RETURN


* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
FILE 2
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

From waldo@clinet.UUCP Sun Jan 31 04:16:28 1988
Path: brspyr1!steinmetz!uunet!mcvax!enea!tut!santra!clinet!waldo
From: waldo@clinet.FI (Tuomas Siltala)
Newsgroups: comp.sys.cbm
Subject: ENCODE/DECODE for C64
Message-ID: <585@clinet.FI>
Date: 31 Jan 88 09:16:28 GMT
Reply-To: waldo@clinet.UUCP (Tuomas Siltala)
Organization: City Lines Oy, Helsinki, Finland
Lines: 44


begin 600 clinet
M`0@+"```GC(P-C$```"I-H4!(.?_J0R@A2#["ZD/H@B@#R"Z_ZD`(+W_(,#_
M(.3_R2#0^:(/(,G_J4D@TO\@S/^I`:((H``@NO^I`J)?H`X@O?\@P/^B`2#&
M_R#D_R#D_R#D_R#D_]`#3/\((.3_T`8@Y/],O0C)O_`"L$$@Y/_0/*D`C5T.
MH`(@Y/_)(M#Y(.3_R2+P!YE@#LA,CP@@Y/_)(/#YC5T.J0"98`Z,7@X@S/^M
M70[)4/`,R5/P""#D_]#[3&`((,S_J0R@Z2#["ZD.H$(@^PNI#J!B(/L+J0T@
MTO\@Y/_)6?`OR4[0]:(#J9$@TO_*T/JB`2#&_TR]""#,_ZD!(,/_J0\@P_^I
M#:`$(/L+J3>%`6`@S/^I`2##_Z(/(,G_J0*B"*`"(+K_K5X.HF"@#B"]_R#`
M_R`-#,DP\`-,[@NB`B#&_ZD`A?VI$(7^J0V@'R#["Z``(.3_D?W(T`+F_J60
M\/*$_2#,_R`-#,DP\`-,[@NI`B##_ZD-H#,@^PL@*PRL<PZ,?@ZY<PZ9?@Z(
MT/>I#:`_(/L+("L,K',.C(D.N7,.F8D.B-#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/1$52#0T-("`@24Y315)4($1)4TL@5$\@0D4@14Y#3T1%
M1"]$14-/1$5$#0T-("`@("`@("`@("!!3D0@4%)%4U,@/%-004-%/@T-`"`@
M($Q/040@5$A)4R!&24Q%("A9+TXI/PT-`"`@(!$1+2TM+2T@3D\@1DE,15,@
M+2TM+2T-``T@("!,3T%$24Y'($9)3$4N#0T`("`@0T]$12`Q.B``("`@0T]$
M12`R.B``'CI615))1ED@0T]$12Q3+%(>.E9%4DE&62!#3T1%+%,L5Y,1$1$@
M("`25U)/3D<@0T]$12X-#0"3$1$1("`@0T]$12!615))1DE%1`T-`"`@($5.
M0T]$12]$14-/1$4@4$A!4T4@0T]-4$Q%5$4N#0T`("`@5U))5$E.1R!&24Q%
M(%1/($1)4TLN#0T`("`@1DE,12!354-#15-31E5,3%D@0T]0245$(%1/($1)
M4TLN#0T`("`@$E!23T-%1%5212!!0D]25$5$+@T-`"`@(!)#3T1%(#(@3553
M5"!"12!32$]25$52(%1(04X@0T]$12`Q+@T-`"`@("`@("`@("`@("`@("`@
M("`-D2`@(```````)#`Z("`@("`@("`@("`@("`@(```````````````````
M````````````````````````````````````````````````````````#0T-
M#0``````````````````````````````````````````````````````````
E````````````````````````````````````````````````````
`
end


* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-- 
"CROOK ROBS 16 BANKS --              Dave Fiske  (davef@brspyr1.BRS.COM) 
 WITH A CUCUMBER"                
                                     Home:  David_A_Fiske@cup.portal.com
Headline from Weekly World News             CIS: 75415,163  GEnie: davef

acliu@skat.usc.edu (Alex C. Liu) (12/23/89)

In article <6579@brspyr1.BRS.Com> davef@brspyr1.BRS.Com (Dave Fiske) writes:
>A short while ago, someone was looking for some UUENCODE/UUDECODE stuff
>that had been posted on the net ages ago.  I thought I had saved it,
>but couldn't locate it, until today, when I found two compressed files
>in my Humor subdirectory.  Why I stored them there, I don't know, but
>at least I found them.

	[ Some people actually think it is funny that you would try to
	  implement uuencode/uudecode on a C64/128! :) ]

>There is a UUENCODE program in BASIC, and it is pretty easy to follow.

Yes the program is well written, and runs in 64 and 128 mode.  It has
some Quircks, though, It creates a STANDARD ASCII file, so when you
upload the file, you must make sure your term program won't try to
Convert what it thinks is a PETASCII code into standard ASCII.  (You
will end up wrong info)  Also, the program ends a Line with a CR
(CHR$(13)) which is not that smart on a Unix/amiga system that likes
an LF (CHR$(10)) or on a CPM/MS-DOS system, that likes a CRLF.
Besides that the program works like a charm...

>The UUDECODE/UUENCODE program is, unfortunately, uuencoded.  Thus,
>you have to have a way to uudecode it before you can use it. 
>This sounds insane, but actually, if you can get the file to a PC or
>mini-computer where you already have uudecode, you can transfer it in
>binary fashion to your C-64, and you would then have a working version.

Well, that file (Called CLINET when uudecoded) is NOT a uudecode
program.  It will Encode the program in some fashion but that is NOT
UUencoding.  It is most likely to be a Cyphering program for DATA
SECURITY.  Yes, I know, I wish there is a UUdecode program for the
C64/128, but this one Ain't it!

>Also, I should point out that I have never tried either of these.  I
>saved the BASIC program, just because it was an easy way to see how
>UUENCODE works, and I saved the uuencoded file with the idea that
>someday I might make the effort to actually transfer it onto my 64.
>(I still haven't.)

I already did.  Nice try, and you got the thing ALMOST right... (I
mean one program right out of two is not that bad! ;-) :-)



______________________________________________________________________
Alex C. Liu                   | INTERNET: acliu%skat@usc.edu
Voice: (213) 749-2730         | BITNET: acliu%skat@gamera
Q-Link: Alejandro             | UUCP: ...!usc!edu

Southern-Comfort@cup.portal.com (E Roland Leeton) (12/24/89)

Thanks for posting the programs.  Now if you'd be so kind as to
explain the "enter code 1" and "enter code 2" in the program I
just decoded from your file.  In other words, I have it, it
apparently works, but I apparently am not brilliant enough to
figure it out with some sort of documentation.
In other words, thanks, but HELP!!!

bowen@cs.Buffalo.EDU (Devon Bowen) (12/24/89)

In article <21932@usc.edu>, acliu@skat.usc.edu (Alex C. Liu) writes:
> Yes the program is well written, and runs in 64 and 128 mode.  It has
> some Quircks, though, It creates a STANDARD ASCII file, so when you
> upload the file, you must make sure your term program won't try to
> Convert what it thinks is a PETASCII code into standard ASCII.  (You
> will end up wrong info)  Also, the program ends a Line with a CR
> (CHR$(13)) which is not that smart on a Unix/amiga system that likes
> an LF (CHR$(10)) or on a CPM/MS-DOS system, that likes a CRLF.

I wrote it to match my upload program.

> Besides that the program works like a charm...

If you've got a few hours. I wrote that program cause I needed to upload
some screen dumps one weekend. Haven't used it since. The only reason I
even posted it was to demonstrate how uuencoding works. It's actually quite
horrible...

Devon