home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Overload
/
ShartewareOverload.cdr
/
progm
/
cpgms.zip
/
CRYPT.C
< prev
next >
Wrap
Text File
|
1985-08-05
|
2KB
|
93 lines
/*
* crypt: a file encryption utility
*
* by Andrew Scott Beals
* 9178 Centerway Rd.
* Gaithersburg MD 20879
* (301) 926-0911
* last update->26 June 1982
*
*/
#include "stdio.h"
main(argc,argv)
int argc;
char *argv[];
{
char rotor[128];
char rotsiz;
int byte;
char rotptr;
char filout;
FILE *input, *output;
if(argc == 2 && argv[1][0] == '?') {
printf("crypt is a program designed to provide\n");
printf("the user with a means to protect his data\n");
printf("from the perusal of others, even if they\n");
printf("can get their hands on his file\n\n");
printf("usage: crypt [ -K <key> ] <input file> [ <output file> ]\n");
exit(1);
}
if(argc > 5 || argc < 2) {
printf("usage: crypt [ -K <key> ] <input file> [ <output file> ]\nfor more information, enter: crypt ?");
exit(1);
}
if(argv[1][0] == '-' && argv[1][1] == 'K') {
strcpy(rotor,argv[2]);
argc-=3; /* make argc == # of files spec */
argv+=3; /* argv now points to the first file name */
}
else {
printf("key? ");
scanf("%s",rotor);
argc--;
argv++;
}
if((input = fopen(argv[0], "r")) == NULL) {
printf("can't open %s for input",argv[0]);
exit(1);
}
if(argc == 2) { /* open up the output file */
filout=1;
if((output = fopen(argv[1], "w")) == NULL) {
printf("can't open %s for output",argv[1]);
exit(1);
}
}
else
filout=0;
rotsiz=strlen(rotor);
if(!rotsiz) {
printf("funny guy...the key must be at least 1 character");
exit(1);
}
rotptr=1;
printf("Working...");
while((byte=getc(input)) != EOF) {
byte ^= rotor[rotptr++];
rotptr %= rotsiz;
if(filout)
putc(byte, output);
else
putchar(byte);
}
if(filout) {
fclose(output);
}
exit(0);
}