home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************
- * encrypt.c
- *
- * Microsoft C Vers 1.03 James Bumgardner 11-Sep-86
- * (818)-766-0594
- *
- * This program, and the associated header file are for encrypting text
- * which is otherwise discernable through the use of a debugger or
- * other dumping program. Some possible uses are:
- *
- * - Protecting Copyright and Author/Origin Messages
- * - Scrambling Passwords
- * - Preventing Game Players from cheating
- *
- * To use this program, you must #include the header file "decrypt.h" in
- * your source code. Use the decrypt() function on strings to be scrambled.
- * For example:
- *
- * puts("Copyright (c) 1986 James Bumgardner");
- *
- * would be changed to:
- *
- * puts(decrypt("Copyright (c) 1986 James Bumgardner"));
- *
- * Then make a text file which contains exact duplicates of each string
- * to be encrypted. Each string should be on a separate line. The lines
- * should be ordered as they appear in the object file. There is
- * currently an arbitrary limit of 256 characters per string. Only
- * ascii printing characters are allowed (e.g. 32-127).
- *
- * After you compile/link the file, use ENCRYPT.EXE to scramble the text.
- * Note: Until Encrypt is run, the decrypted lines will be output as garbage
- * when your program is run. Also, Encrypt should only be run once
- * per object file - decrypt can't decode multiple passes.
- *
- * Syntax:
- * ENCRYPT <datafile> <objfile> [<outfile>]
- *
- * <datafile> is the text file containing the strings to look for.
- * <objfile> is the object file that will be encrypted.
- * <outfile> is the output filename.
- *
- *************************************************************************/
-
- #include <stdio.h>
- #include "decrypt.h"
-
- #define TRUE 1
- #define FALSE 0
-
- int _fmode = 0x0000;
-
- FILE *datafile,*objfile,*outfile;
-
- main(argc,argv)
- char *argv[];
- {
- static int c,nchars = 0,nlines = 0;
- static char cline[CRYPTMAX + 1],*cp;
-
- if (argc != 4) {
- printf("Syntax:\n\t ENCRYPT datafile objfile [outfile]\n\n");
- clean_exit(0);
- }
- if ((datafile = fopen(argv[1],"r")) == NULL) {
- printf("Can't open datafile %s\n",argv[1]);
- clean_exit(0);
- }
- _fmode = 0x8000; /* open as binary files */
- if ((objfile = fopen(argv[2],"r")) == NULL) {
- printf("Can't open objfile %s\n",argv[2]);
- clean_exit(1);
- }
- if ((outfile = fopen(argv[3],"w")) == NULL) {
- printf("Can't open outfile %s\n",argv[3]);
- clean_exit(2);
- }
- cprintf("Chars Read Lines Encrypted\n");
- if (cp = fgets(cline,CRYPTMAX,datafile)) {
- cline[strlen(cline) - 1] = '\0';
- if (*cp == '\0') {
- printf("Blank Line in Input File\n");
- clean_exit(3);
- }
- }
- while ((c = getc(objfile)) != EOF) {
- if ((nchars++ % 100) == 0)
- cprintf("\r %8d %3d",nchars,nlines);
- if (cp) {
- if (c != *cp) {
- if (cp != cline) {
- fwrite(cline,1,(int) cp - (int) cline,
- outfile);
- cp = cline;
- }
- putc(c,outfile);
- }
- else {
-
- if (*cp == NULL) {
- fwrite(encrypt(cline),1,strlen(cline)+1,
- outfile);
- if (cp = fgets(cline,CRYPTMAX,datafile)) {
- cline[strlen(cline) - 1] = '\0';
- if (*cp == '\0') {
- printf("Blank Line in Input File\n");
- clean_exit(3);
- }
- }
- cprintf("\b\b\b%3d",++nlines);
- }
- else {
- ++cp;
- }
- }
- }
- else {
- putc(c,outfile);
- }
- }
- if (cp)
- printf("\n\nCouldn't Encrypt: \n%s\n(And subsequent lines)\n",cline);
-
- printf("\n\n%d chars written to file %s\n",nchars,argv[3]);
- clean_exit(3);
- }
-
- clean_exit(n)
- {
- switch (n) {
- case 3: fclose(outfile);
- case 2: fclose(objfile);
- case 1: fclose(datafile);
- }
- exit();
- }