Article View: comp.lang.postscript
Article #3097Re: Encrypting portions of PS file
From: Woody Baker Eagle Signal
Date: Thu, 13 Sep 1990 22:33
Date: Thu, 13 Sep 1990 22:33
200 lines
4696 bytes
4696 bytes
In article <1660@shodha.enet.dec.com>, p_davis@epik.enet.dec.com (Peter Davis) writes:
>
> I've noticed that font files, from Adobe at least, typically contain some
> preliminary stuff in plain old "readable" PostScript, but then the actual glyph
> definitions appear to be encoded in some way.
>
> I'd like to encrypt the prolog of PostScript files my application in generating,
> and then revert to plain text PostScript for the remainder of the file. Does
> anyone know if this is possible? How?
>
> Thanks.
> -pd
#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);
};
infile=fopen(argv[1],"rb");
outfile=fopen(argv[2],"wb");
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);
}
/* Quickie to convert postscript from stdin to eexec format on stdout */
#include "stdio.h"
static unsigned short buffer = 0xd971;
static unsigned long startup = 0xac7252f3; /* 00000000or whatever you want */
main(argc,argv)
char *argv[];
int argc;
{
unsigned char input;
unsigned char output;
int init = 4;
int i;
int result;
FILE *infile,*outfile;
if(argc !=4)
{
printf("usage: encrypt startkey(long hex) infile outfile\n");
}
infile=fopen(argv[2],"r");
outfile=fopen(argv[3],"wb");
sscanf(argv[1],"%lx",&startup);
fprintf(outfile,"%08lx",startup);
for (i=0;i<4;++i)
{
input = (startup >> ((3-i)*8));
buffer = (input + buffer) * 0xce6d + 0x58bf;
}
for(;;)
{
for (i=0;i<(32-init);++i)
{
input = result = fgetc(infile);
if ((int)result == EOF)
break;
output = (input ^ (buffer>>8));
buffer = (output + buffer) * 0xce6d + 0x58bf;
fprintf(outfile,"%02.2x",output);
}
init = 0;
fprintf(outfile,"\n");
if ((int) result == EOF)
break;
}
fclose(infile);
fclose(outfile);
}
/* Quickie to convert eexec format from stdin to postscript on stdout */
#include <stdio.h>
/* Written by Carsten Wiethoff 1989 */
/* You may do what you want with this code,
as long as this notice stays in it */
static unsigned short buffer = 0xd971;
main()
{
unsigned int input;
char output;
int ignore = 4;
int result;
do
{
result = scanf(" %2x",&input);
if ( (result == EOF) || (result == 0) )
break;
output = input ^ (buffer>>8);
buffer = (input + buffer) * 0xce6d + 0x58bf;
if ( ignore > 0 )
{
ignore--;
}
else
{
printf("%c",output);
}
} while (1);
}
/* Quickie to convert postscript from stdin to eexec format on stdout */
#include "stdio.h"
static unsigned short buffer = 0xd971;
static unsigned long startup = 0xac7252f3; /* 00000000or whatever you want */
main()
{
unsigned char input;
unsigned char output;
int init = 4;
int i;
int result;
printf("%08lx",startup);
for (i=0;i<4;++i)
{
input = (startup >> ((3-i)*8));
buffer = (input + buffer) * 0xce6d + 0x58bf;
}
for(;;)
{
for (i=0;i<(32-init);++i)
{
input = result = getchar();
if ((int)result == EOF)
break;
output = (input ^ (buffer>>8));
buffer = (output + buffer) * 0xce6d + 0x58bf;
printf("%02x",output);
}
init = 0;
printf("\n");
if ((int) result == EOF)
break;
}
}
Cheers
Woody
Technical Details
Message-ID:
<1577@chinacat.Unicom.COM>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!chinacat!woodyReferences:
<1660@shodha.enet.dec.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!chinacat!woody From: woody@chinacat.Unicom.COM (Woody Baker @ Eagle Signal) Newsgroups: comp.lang.postscript Subject: Re: Encrypting portions of PS file Summary: here you go Message-ID: <1577@chinacat.Unicom.COM> Date: 13 Sep 90 22:33:06 GMT References: <1660@shodha.enet.dec.com> Organization: a guest of Unicom Systems Development, Austin Lines: 201