I need desperate help.
Ill virtually take a knee and kiss your feet if you help me out.
I'll probably take it on the chops for this but here's your encryptor/decryptor, tested and working in 53 lines...
(This is your one and only freebie... from here follow the 4 steps: Analyse -> Plan -> Write -> Test, that's exactly what I did.)
crypt.c (compile as crypt.exe)
Code:
// file encrypt and decrypt example
// encrypt and dectypt using char + key * 2
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char *argv[])
{ int crypt; // encryption key
int fval; // file values
FILE *infile, *outfile;
if(argc < 4)
{ printf("File encryptor/dectyptor...\n");
printf("Encrypt or decrypt a file based based on a secret method\n\n");
printf("Usage : \n");
printf(" crypt <key> <sourcefile> <outputfile>\n\n");
printf("Key :\n");
printf(" To encrypt enter a single character as your encryption key\n");
printf(" To decrypt enter * as the key\n\n");
printf("Examples :\n");
printf(" crypt x mywork.txt safework.txt\n");
printf(" crypt * safework.txt homework.txt\n\n");
exit(255); }
// open the files
infile = fopen(argv[2],"r");
if (! infile)
{ printf("Unable to open input file\n\n");
exit(254); }
outfile = fopen(argv[3],"w");
if (! outfile)
{ printf("Unable to open output file\n\n");
exit(253); }
// active encryptor
if ((argv[1][0] == '*'))
{ printf("Decrypting...\n\n");
// first value in the file is the key
if ( fscanf(infile,"%d",&crypt) > 0)
while(fscanf(infile,"%d",&fval) > 0)
fputc((fval/2) - crypt,outfile); }
else
{ printf("Encrypting...\n\n");
// set key as first value in file}
fprintf(outfile,"%d ",argv[1][0]);
while( (fval = fgetc(infile)) > 0 )
fprintf(outfile,"%d ", (fval + argv[1][0]) * 2); }
fclose(infile);
fclose(outfile);
printf("Done...\n\n\n");
return 0; }