In order to ensure that your data is not illegally stolen by others, it is necessary to properly encrypt the data file. This procedure takes certain algorithm, encrypts the password and the data, produces a self decrypted exe file. This self decryption file is made up of two parts. The first part of the executable code, its role is to judge the password, to decrypt the data, the latter part of the password and data is encrypted.
This program is divided into two modules for writing. The first is MAIN.C, which is used to encrypt, produce EXE file, the second is main2.c, it is used to decrypt. Compile and generate Main.exe and Main2.exe, and then merge them separately.
The merge method is as follows:
copy/b Main. Exe+main2.exe Key.EXE (note main. Order of Exet and Main2.EXE)
When used, type in the following format.
Key〈 to encrypt file 〉〈 after the creation of EXE filename
When prompted for a password, the specified executable is generated. Run this executable file when decrypting. Enter the password (if the input three times are not correct, will exit the decryption program), that is, the original file content restored to the file you specified. The decryption program is formatted as follows.
Executable file name (filename)
The source program is as follows:
First source code file MAIN.C
#include "stdio.h"
Main (int argc,char *argv[])
{FILE *fp0, *FP1, *FP2;
Char ch,*password,i,str[10]; PASSWORD=STR;
if (argc!=3)
{printf ("Usage:key");
Exit (0);
}
if ((Fp0=fopen (argv[0), "RB") =null)
{printf ("can ' t open%s", argv[0]);
Exit (0)
}
if (fp1= fopen (Argv[1], "R") =null)
{printf ("can ' t Open%s") argv[1]);
exit (0);
}
if (Fp2=fopen (argv[2], WB))
{printf ("can ' t open%s", argv[2]);
}
password= (char *) getpass ("Please input password:");
Fseek (Fp0,1394ol,seek_set);/* 13940 is the length of the Main.exe file, and different work environments have different values. Please modify the actual length */
while (!feof (fp0))
Fputc (fgetc (fp0), FP2);/* Enter main2.exe into FP2 specified file */
for i=0;password[i]!= ' i++)
{FPUTC ((I+password[i]) &I,FP2);/* Encrypt password to write to file */
}
Fputc (' Ten ', FP2), * * put "10" in Password */
do{
{for i=0;password[i]!= ', i++
{ch=fgetc (FP1)/* Read a character */
if (feof (FP1)) break from the file you want to encrypt;
Ch=ch&password[i ];
Ch+=i;
Ch=nch/* Writes this character to the FP2 specified file */
FPU after it has been calculated with the password I valueTC (CH,FP2);
}
}while (!feof (FP1));
Fcloseal?;
}