#include #include #include unsigned long a,b[128],index2; unsigned int r,cle; /* CARACACHS Cipher (c) Alexandre PUKALL 2000 */ /* 256 bits CIPHER */ /* Code free for all, even for commercial application */ /* Public domain */ int stream(unsigned int *r,unsigned long *index2,unsigned long *a,unsigned long *b) { b[*index2] = ( b[*index2] * (*a) ) + 1; *r = (*r + (( b[*index2] >> 16 ) & 0x7fff)); *r = (*r << (*r%16)) | (*r >> (16-(*r%16))); return(0); } unsigned char pc3encode(unsigned char byte) { unsigned short d; for (index2=0;index2<=(cle-1);index2++) { stream(&r,&index2,&a,b); } d=byte; byte=byte^(r&255); r=r+d; b[cle-1]=b[cle-1]+d; return(byte); } unsigned char pc3decode(unsigned char byte) { unsigned short d; for (index2=0;index2<=(cle-1);index2++) { stream(&r,&index2,&a,b); } byte=byte^(r&255); d=byte; r=r+d; b[cle-1]=b[cle-1]+d; return(byte); } int pc3init(unsigned int lngkey,unsigned char key[258]) { unsigned int z,y,x,i,reste; unsigned char tab[258],plain; if (lngkey>256) lngkey=256; if (lngkey<1) { lngkey=1; strcpy(key,"a"); } x=lngkey; for (i=0;i=x) i=0; } reste=lngkey%2; cle=lngkey/2; if (reste!=0) cle=cle+1; for (z=0;z<128;z++) { b[z]=0; } y=0; for (z=0;z<=(cle-1);z++) { if ( (z==(cle-1))&&(reste!=0) ) { b[z]=(tab[y]*256)%65536; } else { b[z]=((tab[y]*256)%65536)+tab[y+1]; y=y+1; } y=y+1; } for (z=0;z