#include /* Program: ROX (dlok) Type: Command line XOR encryption utility Coder: Dave Published at: scripts.tropicalpcsolutions.com Language: C Assembly: WIN - Borlands C++ command line compiler v5.5.1 LINUX - gcc v 3.3.3 */ // How much data to overwrite, 1.E5 = roughly 1 megabyte, 2.E5 will = roughly 2 megabytes etc... #define overWrite 1.E5 int usage(void); int usage() { printf("\nROX v1.2 - XOR encryption program by Dave from TPCS. \n"); printf("\n=======================USAGE========================== \n\n"); printf("Win32 - C:\\>ROX [-d] \n"); printf("Linux - [foo@bar]$ ./ROX [-d] \n\n"); printf("Optional -d switch will overwrite and delete original file.\n"); exit(0); } int main(int argc, char *argv[]) { FILE *originalData, *encryptedData; int byte, character, x, i, argComp; char delSwitch[] = "-d"; // If user enters wrong number of args display usage if(argc != 4 && argc != 5) usage(); // Try to open original file for reading : display error if there is a problem if((originalData = fopen(argv[1], "rb")) == NULL) { printf("\nError opening %s\n\n", argv[1]); exit(0); } // Try to open/create new encrypted file for writing: display error if there is a problem if((encryptedData = fopen(argv[2], "wb")) == NULL) { printf("\nError opening %s\n\n", argv[2]); exit(0); } // Loop through file character by character until the end while((character = getc(originalData)) != EOF) { // encrypt each character using XOR and your key value character = character ^ *argv[3]; byte++; putc(character, encryptedData); } fclose(originalData); fclose(encryptedData); // If user adds 5th arg (possible -d switch) if(argc == 5) { // compare the arg value with hardcoded value (-d) argComp = strcmp(delSwitch,argv[4]); // If user entered -d switch then overwrite original file... if(argComp==0) { // Overwrite file 7 times : change this if you want for(x=0;x<7;x++) { // open original file for overwrite process originalData = fopen(argv[1], "wb"); //Overwrite 1.E5 times for(i=0;i 3) fprintf(originalData, "-*-°TPCS°-€r姀Ð-*-"); } fclose(originalData); } //and delete original file remove(argv[1]); return 0; } } }