How do you send a binary file to somebody with a plain MS-DOS or Windows based install, assuming the person can receive via email only text files less than 5 kilobytes without attachments? This is a bootstrapping problem, and using the wonderful utility DEBUG.COM present on all these systems, it can be accomplished with the following simple program. After sending this program once, you can sent arbitrary binary files in little plain text pieces.
The program decodes text files encoded in base64 encoding and is RFC 1341 compliant. The program errs on the side of caution, decoding files even if they contain illegal characters or the number of legal characters is not an exact multiple of 4.
To compile the following program save it to a file named decode.asm and type in a DOS prompt:
debug < decode.asmThis should create an 844 byte decode.com file.
To run the program use stdin and stdout, for example to convert a base64 encoded file in.txt to the binary out.jpg type:
decode < in.txt > out.jpg
Thanks go to Jan Aleman
(Professional Data Management)
for the great idea to use DEBUG to do the programming.
Also useful were the cool DEBUG tutorial by Fran Golden at
http://www.datainstitute.com/debug1.htm, and the assembly reference at http://members.tripod.com/~Vitaly_Filatov/ng/asm/.
The source (decode.asm) is short and simple, and can be mailed as a plain text file which is less than 2 kilobytes:
a 100 jmp 34e DB 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/$' DB 'Error.' 0a 0d DW 0 a 34e mov ah,44 mov al,0 mov bx,0 int 21 mov ah,44 mov al,1 or dx,20 int 21 mov di,0 mov si,0 call 371 jnc 367 call 41c int 20 mov bx,0 call 3c7 jc 3ac or bl,al mov cl,6 shl bx,cl call 3c7 jc 3ac or bl,al mov cl,4 shl bx,cl call 3e3 shl bx,1 shl bx,1 call 3c7 jc 3ac or bl,al mov cl,6 shl bx,cl call 3e3 call 3c7 jc 3ac or bl,al mov bh,bl call 3e3 clc ret push ax mov bx,0 mov ah,[103+bx] cmp ah,24 jz 3c1 cmp ah,al jz 3c4 inc bx jmp 3b1 stc jmp 3c5 clc pop ax ret push bx cmp di,[14c] jne 3d3 call 3f2 jc 3e1 mov al,[14e+di] inc di call 3ad jnc 3df jmp 3c8 mov al,bl pop bx ret cmp si,100 jnz 3ec call 41c mov [si+24e],bh inc si ret push ax push bx push cx push dx mov ah,3f mov bx,0 mov cx,100 mov dx,14e int 21 jnc 408 call 43d mov [14c],ax cmp ax,0 jne 413 stc jmp 414 clc mov di,0 pop dx pop cx pop bx pop ax ret push ax push bx push cx push dx mov ah,40 mov bx,1 mov cx,si mov dx,24e int 21 jnc 431 call 43d sub si,cx je 438 call 43d pop dx pop cx pop bx pop ax ret mov ah,40 mov bx,2 mov cx,8 mov dx,14c int 21 int 20 n decode.com r cx 34c w q