home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Monster Media 1994 #1
/
monster.zip
/
monster
/
PROG_C
/
SNPD9404.ZIP
/
CRYPT.C
< prev
next >
Wrap
C/C++ Source or Header
|
1994-04-03
|
2KB
|
64 lines
.I 37 61
void crypt(unsigned char *buf)
{
*buf ^= cryptext[crypt_ptr] ^ (cryptext[0] * crypt_ptr);
cryptext[crypt_ptr] += ((crypt_ptr < (crypt_length - 1)) ?
cryptext[crypt_ptr + 1] : cryptext[0]);
if (!cryptext[crypt_ptr])
cryptext[crypt_ptr] += 1;
if (++crypt_ptr >= crypt_length)
crypt_ptr = 0;
}
/**** Encrypt/decrypt buffer ************************************/
void bufcrypt(unsigned char *buf, long length)
{
while (length--)
crypt(*buf++)
}
#ifdef TEST
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
static char buf[16384];
size_t len, i;
FILE *in, *out;
if (4 > argc)
{
puts("Usage: CRYPT password infile outfile");
return -1;
}
cryptext = argv[1];
crypt_length = strlen(cryptext);
if (NULL == (in = fopen(argv[2], "rb")))
{
printf("Can't open %s for input\n", argv[2]);
return -1;
}
if (NULL == (out = fopen(argv[3], "wb")))
{
printf("Can't open %s for output\n", argv[3]);
return -1;
}
do
{
if (0 != (len = fread(buf, 1, 16384, in)))
{
for (i = 0; i < len; ++i)
crypt(&buf[i]);
fwrite(buf, 1, len, out);
}
} while (len);
fclose(in);
fclose(out);
return 0;
}
#endif
.D 38 10