Command Line Example:
Command 1: sudo gcc -o encrypt encrypt.c
Command 2: ./encrypt
Note: ...you can copy encrypt to /bin ....
C++ Include Files:
#include
#include
#define KEY_LENGTH 66 * 6
unsigned char Random_Byte(void)
{
double result;
result = (double) rand() / (double) RAND_MAX;
result = result * 255.0;
return (unsigned char) result;
}
void Crypt(FILE *input, FILE *output)
{
unsigned char key[KEY_LENGTH];
int key_index, in_value;
unsigned char out_value, random_value;
int done;
/* create random key */
for (key_index = 0; key_index < done =" 0;" in_value =" fgetc(input);">= 0)
{
out_value = (unsigned char) in_value;
random_value = Random_Byte();
for (key_index = 0; key_index < out_value =" out_value" out_value =" out_value" done =" 1;" done =" 0;" in_value =" fgetc(input);">= 0)
{
random_value = (unsigned char) in_value;
in_value = fgetc(input);
if (in_value >= 0)
{
out_value = (unsigned char) in_value;
out_value = out_value ^ random_value;
for (key_index = (KEY_LENGTH - 1); key_index >= 0; key_index--)
out_value = out_value ^ key[key_index];
fputc(out_value, output);
}
else
done = 1;
}
else
done = 1;
} /* end of while */
printf("Decrypting file..");
} /* end of Decrypt() */
int main(int argc, char *argv[])
{
FILE *input, *output;
if (argc <>
printf("Use the `e' option to encrypt in_file, producing out_file.\n");
printf("Use the `d' option to decrypt out_file giving in_file.\n");
printf("Example: Encrypt c plain.txt coded.txt\n");
printf(" Encrypt d coded.txt newplain.txt\n");
printf("\n Encryption By Johnny Buckallew Stroud\n");
return 0;
}
if ( (argv[1][0] != 'e') && (argv[1][0] != 'd') )
{
printf("First agument must be `e' or `d'.\n");
return 1;
}
input = fopen(argv[2], "r");
if (!input)
{
printf("Cannot open %s for reading.\n", argv[2]);
printf("Command Example: sudo encrypt e %s outfile.doc \n", argv[2]);
return 1;
}
output = fopen(argv[3], "w");
if (!output)
{
printf("Cannot open %s for writting.\n", argv[3]);
printf("sudo encrypt e input.doc %s", argv[3]);
fclose(input);
return 1;
}
printf("Working......");
srand( time(NULL) );
if (argv[1][0] == 'e')
Crypt(input, output);
else
Decrypt(input, output);
printf("....Done.\n");
fclose(input);
fclose(output);
return 0;
} /* end of main() */
No comments:
Post a Comment