Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!sri-spam!ames!jaw From: jaw@ames.UUCP (James A. Woods) Newsgroups: comp.sources.d Subject: Towards minimalist self-decompressing 'shar'chives Message-ID: <1666@ames.UUCP> Date: Mon, 1-Jun-87 23:52:48 EDT Article-I.D.: ames.1666 Posted: Mon Jun 1 23:52:48 1987 Date-Received: Wed, 3-Jun-87 04:44:07 EDT Organization: NASA Ames Research Center, Moffett Field, CA Lines: 82 Summary: further microsurgery on a twisted concept # "You've heard of Ali Baba -- forty thieves had he. Out for what we all want: lots of LSD." -- V. Stanshall Re-directing a discussion from comp.sys.sources started by Karl Fox, below we append the production version of a self-decompressing sharchive maker. It's yet another few hundred characters shorter (mainly from combining 'atob' and 'zcat' into one program), but not enough to qualify for 4th International Obfuscation Contest status! The 1991-character script still has a little fat in the way of "literary" allusion, preserved at amazing cost for sheer perversity. This one offers more robust tempfile handling, swifter execution due to the single compilation, but more importantly, capability to completely short-circuit the compile if the requisite code is already installed on the target system. Raison-d'etre for this 'shar' remains its inherent nose-thumb at what kind/version of decoding the other side might entertain. You can change things right out from under the recipient if desired, without need for a "courier" to deliver the "key". The basic idea probably goes back to Claude Shannon. A contraindication for the shar would be for packaging USENET postings, since the transport mechanism already does compression. However, it should be just the ticket for a UNIX archive server. -- James A. Woods (ames!jaw) P.S. I dedicate the opaque-yet-functional brevity of what follows to Donovan Fong, wherever he may be. -------------- a bent 52-line compressing 'shar' machine ------------ echo '#!/bin/sh # "Cleverly he dialed from within." -- D. Van Vliet, "Trout Mask Replica" trap "rm -f zcat atob az$$*;exit" 0 1 2 3 15 echo decoding... cat>az$$.c<<\_' cat<<'TROUSER PRESS' #include #define d define #d R register #d I if #d E else #d W while #d C char #d L long #d U unsigned #d B(n) (1<<(n)) #d K bcount #d G getchar() #d P putchar #d X return #d J 255 #d H(n) ((C*)h)[n] #d V(a,b) (a&(B(b)-1)) #d Q 256 #d Y w=w*85+c-'!', #d Z w=Q;W(w--)t[w]=0 #d x break; #d F {fprintf(stderr,"shar botch: resend\n");X;} L K,o,v,w,c,m,M=B(16),f;int i,q,b,n,k=16,e=128,j,O,S;U short t[69001];U L h[69001];C D[J];FILE*T;d(c)R c;{I(c=='z'){I(K)F E{c=4;W(c--)y(0);}}E I(c>='!' &&(c<'!'+85)){I(!K)w=c-'!',++K;E I(K<4)Y++K;E Y y(w>>24),y(w>>16),y(w>>8),y(w) ,w=K=0;}E F;}y(l)L l;{R c=(int)(l&J);o^=c;m+=c;m++;I(f&(1<<31))f*=2,f++;E f*=2 ;f+=c;putc(c,T);}main(g,v)C**v;{R c;L i;L A,h,y,s,r;I(**v!='a')X(a());sprintf( D,mktemp("azXXXXXX"));I(!(T=fopen(D,"w+")))F;unlink(D);W(1){I(!fgets(D,J,stdin ))F;I(!strcmp(D,"xbtoa Begin\n"))x}W((c=G)>=0){I(c=='\n')continue;E I(c=='x')x E d(c);}I(scanf("btoa End N %ld %lx E %lx S %lx R %lx\n",&A,&h,&y,&s,&r)!=5)F; I(A!=h||y!=o||s!=m||r!=f)F E{fseek(T,0L,0);i=A;W(i--)P(getc(T));}}L g(){R C*p= D;I(j>0||O>=S||f>m){I(f>m)m= ++n==k?M:B(n)-1;I(j>0)m=B(n=9)-1,j=0;S=fread(D,1, n,stdin);I(S<1)X-1;O=0;S=S*8-n+1;}q=O;b=n;p+=q>>3;q&=7;c=V(*p++>>q,8-q);q=8-q; b-=q;I(b>7)c|=(*p++&J)<16)F;z();}z(){L w;R C*s;m=B(n=9)-1;Z,H(w)= (C)w;f=e?257:Q;i=o=g();I(o==-1)X;P((C)i);s=(C*)&H(B(16));W((w=g())>=0){I(w==Q &&e){Z;j=1;f=Q;I((w=g())==-1)x}v=w;I(w>=f)*s++=i,w=o;W((U L)w>=(U L)Q)*s++= H(w),w=t[w];*s++=i=H(w);do P(*--s);W(s>&H(B(16)));I((w=f)/dev/null 1>&2|| (cc -o zcat az$$.c;ln zcat atob) (atob|zcat|tar xvf -)<<\Feilgau' tar cf - $*|compress|btoa echo "Feilgau"