The guys have given you good advice, but we already have this software, so I post it directly. This is called encryption, please do NOT change the terms! It becomes very hard to figure out what someone is talking about. Especially Americans have this tendency. For example what is [MF, its main function, but written like this, who can guess....We are considering releasing a GUI version of this software with which you can encrypt everything, even .exe files. Test it for yourself to be sure. I don't know if advertisement is allowed on this site, so we can advertise our online shop.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* Function declaration. */
void Encrypt(char * FILENAME, char * NEW_FILENAME);
int main ()
{
char f1[100]; // array big enough to hold expected input
char f2[100]; // array big enough to hold expected input
printf ("Please enter file for processing:\n");
scanf ("%99s", f1); // set max characters to read to prevent buffer overflow
printf ("Please enter the name of the file after processing:\n");
scanf ("%99s", f2);
Encrypt(f1, f2);
return 0;
}
void Encrypt(char * FILENAME, char * NEW_FILENAME)
{
printf("Processing started.\n");
FILE *inFile;
FILE *outFile;
char key[50]; // array big enough to hold expected input
char process[50]; // array big enough to hold expected input
int keylen, keyidx;
int Byte; // fgetc returns int, so use an int
int newByte;
printf ("Please enter 'encryption or decryption'\n");
scanf ("%49s", process);
printf ("Please enter the key\n");
scanf ("%49s", key);
keylen = strlen(key);
keyidx = 0; // starting index into key
printf("Opening files\n");
inFile = fopen(FILENAME,"rb");
outFile = fopen(NEW_FILENAME, "wb");
if(inFile == NULL)
{
printf("Error: Can't Open inFile\n");
}
else if(outFile == NULL)
{
printf("Error: Can't open outFile\n");
}
else
{
printf("File Opened, Encrypting\n");
while((Byte = fgetc(inFile)) != EOF) // read a byte, check if EOF
{
if (!strcmp(process,"encryption"))
{
newByte = Byte + key[keyidx]; // use key index
if (newByte > 255) newByte -= 256; // check for overflow
}
else if (!strcmp(process,"decryption"))
{
newByte = Byte - key[keyidx];
if (newByte < 0) newByte += 256;
}
else
{
newByte = Byte;
}
fputc(newByte, outFile);
keyidx++;
// loop to the start of the key if needed
if (keyidx >= keylen) keyidx = 0;
}
}
if (inFile != NULL) fclose(inFile); // close your files when you're done
if (outFile != NULL) fclose(outFile);
}