Last active
August 5, 2016 21:19
-
-
Save DreamVB/4aa0d05bab47a2c806b0fcf066f92665 to your computer and use it in GitHub Desktop.
Encrypt And Compress - protecting sourcecode and reduceing down time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Encrypt HTML By DreamVB | |
Version 1.0 | |
Encrypt & Compress HTM and HTML files making them harder to read | |
to protect from your code been stolen. | |
There is also a optional /C compression flag that can be used to also reduce the html size. | |
Please feel free to use as you like or if you want add your own features and let me see the changes. | |
Please let me know if you found this code useful e. [email protected] | |
Usage | |
Encrypt only | |
enhtml sample.html output.html | |
Encrypt + Compress | |
enhtml sample.html output.html /C | |
*/ | |
#include <stdio.h> | |
#include <string> | |
char* Hex(int Number) | |
{ | |
char sHex[10]; | |
int i = 0; | |
// Convert to hex number | |
sprintf(sHex, "%02x", Number); | |
// Resize char* to fix sHex | |
char* Str = (char*)malloc(strlen(sHex) * sizeof(char*)); | |
// Copy sHex into Str | |
strcpy(Str, sHex); | |
// Return | |
return Str; | |
} | |
int main(int argc, char* argv[]){ | |
FILE *fin = NULL; | |
FILE *fout = NULL; | |
bool CompFlag = false; | |
char c = '\0'; | |
if(argc < 3){ | |
printf("Usage: <InFile> <OutFile> [/C] COMPRESS\n"); | |
return 0; | |
} | |
//Check for compression flag | |
if(argc == 4){ | |
if(argv[3][0] == '/'){ | |
if((argv[3][1]=='C') || (argv[3][1] == 'c')){ | |
//User wants to compress the file | |
CompFlag = true; | |
} | |
} | |
} | |
//Open inputfile. | |
fin = fopen(argv[1],"r"); | |
//Try and see if inputfile opened. | |
if(fin == NULL){ | |
printf("IO/Error cannot open file\n"); | |
return 0; | |
} | |
//Open output file | |
fout = fopen(argv[2],"w"); | |
//See if output file opened. | |
if(!fout){ | |
printf("IO/Error cannot write file\n"); | |
return 0; | |
} | |
//Add javascript heading code | |
fputs("<Script Language='Javascript'>\n",fout); | |
fputs("<!-- HTML Encryption by DreamVB -->\n",fout); | |
fputs("<!--\n",fout); | |
fputs("document.write(unescape('",fout); | |
while(!feof(fin)){ | |
//Read char | |
c = getc(fin); | |
if(!feof(fin)){ | |
//Check if we need to compress the file. | |
if(CompFlag){ | |
if(c == '\n'){ | |
c = fgetc(fin); | |
//Exit if at end of file | |
if(c == EOF){ | |
break; | |
} | |
//Eat spaces | |
while((c == ' ') || (c=='\t')) | |
{ | |
c = fgetc(fin); | |
} | |
//Eat line breaks | |
if(c == '\n'){continue;} | |
if(c == '\r'){continue;} | |
} | |
} | |
//Check again for compressing TABs | |
if(CompFlag){ | |
if(c == '\t'){ | |
continue; | |
} | |
} | |
if(!feof(fin)){ | |
//Write HEX sign | |
fputc('%',fout); | |
//Write hext value. | |
fputs(Hex(c),fout); | |
} | |
} | |
} | |
//Write ending code | |
fputs("'));\n",fout); | |
//Write comment end code | |
fputs("//-->\n",fout); | |
//Write javascript end tag | |
fputs("</Script>\n",fout); | |
//Close files | |
fclose(fin); | |
fclose(fout); | |
return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment