#include "stdio.h"


/*
	routine takes an encrypted eexec file and creates a
	decrypted eexec file.  First cut is much simpler than
	the full decryption would be.  Full decryption will handle
	multiple keys, and have the flag to encrypt or decrypt things.
*/

FILE *infile,*outfile;

main(argc,argv)
char *argv[];
int argc;
{
int first =4;
int state=0xD971;
int c;
char decrptd;

	if(argc !=3)
		{
		printf("usage:  decrpt infile outfile\n");
		exit(0);
		};
#ifdef MSDOS
	infile=fopen(argv[1],"rb");
	outfile=fopen(argv[2],"wb");
#else
	infile=fopen(argv[1],"r");
	outfile=fopen(argv[2],"w");
#endif	
	while(fscanf(infile,"%2x",&c)>0)
		{
	/*	if(first !=0)	
			{
			first--;
			}
		else
			{ */
			decrptd= c ^ (state >>8);
			if(first !=0)
				{
				first--;
				}
			else
				{	
				fputc(decrptd,outfile);
				}
			state=state + c;
			state=state * 0xCE6D;
			state=state + 0x58BF;
		/*	} */
		}
	fclose(infile);
	fclose(outfile);	
}				
