User:RavynousHunter/GEP/Source

/*

GEP - Generic Encryption Program

Designed by RavynousHunter

A very simple, command-line program to XOR encrypt and decrypt files.




 * 1) include
 * 2) include
 * 3) include
 * 4) include

using namespace std;

void Encrypt(string file_loc, string destination, string dest_filename); void Decrypt(string file_loc, string destination, string dest_filename); void Startup;

int main(int argc, char *argv[]) { Startup; }

void Startup { system("cls");

cout << "GEP - Generic Encryption Program" << endl; cout << "Developed by RavynousHunter" << endl; cout << "---\n\n"; cout << "1) Encrypt\n"; cout << "2) Decrypt\n\n"; cout << ": "; int input; cin >> input; switch(input) {   case 1: {     cout << "\n\nWhat is the path and file name of the file you want to encrypt?"; cout << "\n: "; string loc; cin >> loc; cout << "\n\nWhere do you wish the file to go?"; cout << "\n: "; string dest; cin >> dest; cout << "\n\nFinally, what do you wish the file to be called (w/o extension)?"; cout << "\n: "; string filename; cin >> filename; Encrypt(loc, dest, filename);

break; }   case 2: {     cout << "\n\nWhat is the path and file name of the file you want to decrypt?"; cout << "\n: "; string loc; cin >> loc; cout << "\n\nWhere do you want the file to go?"; cout << "\n: "; string dest; cin >> dest; cout << "\n\nFinally, what do you wish to name this file (please include original extension)?"; cout << "\n: "; string dest_filename; cin >> dest_filename; Decrypt(loc, dest, dest_filename); break; }   default: {     cout << "\n\nInvalid input." << endl << endl; system("PAUSE"); Startup; break; } } }

void Encrypt(string file_loc, string destination, string dest_filename) { string true_dest; // The real destination, with filename system("cls"); // Clear the console of old text. cout << "Generating true destination...\n";

true_dest += destination + dest_filename + ".RH0";

cout << "True destination generated...\n"; ifstream in_file; ofstream out_file; cout << "Generating file streams...\n";

in_file.open(file_loc.c_str, ios::in | ios::binary); if (!in_file.is_open) {   cout << "Error in opening input file, exiting...\n" << endl; system("PAUSE"); system("EXIT"); } out_file.open(true_dest.c_str, ios::out | ios::binary | ios::app); if (!out_file.is_open) {   cout << "Error in opening output (*.RH0) file, exiting...\n" << endl; system("PAUSE"); system("EXIT"); } cout << "File stream generation successful..." << endl;

long size; in_file.seekg(in_file.end); size = in_file.tellg;

in_file.seekg(in_file.beg); vector file_mem((istreambuf_iterator (in_file)), (istreambuf_iterator )); // Encryption begins here, XOR by 128.

for (int i = 0; i < file_mem.size; i++) {   char xor_byte = file_mem[i] ^ 128; out_file << xor_byte; }   // Encryption ends here. in_file.close; out_file.close; cout << "Encrypted file generated at location: " << true_dest.c_str; cout << endl << endl;

system("PAUSE"); system("EXIT"); }

void Decrypt(string file_loc, string destination, string dest_filename) { system("cls");

cout << "Generating true destination..." << endl;

string true_dest = destination + dest_filename;

cout << "True destination generated..." << endl;

ifstream in_file; ofstream out_file;

cout << "Generating file streams..." << endl;

in_file.open(file_loc.c_str, ios::in | ios::binary);

if (!in_file.is_open) {   cout << "Error in opening input file, exiting...\n\n"; system("PAUSE"); system("EXIT"); }

out_file.open(true_dest.c_str, ios::out | ios::binary | ios::app);

if (!out_file.is_open) {   cout << "Error in opening output file, exiting...\n\n"; system("PAUSE"); system("EXIT"); }

cout << "File streams successfully generated..." << endl;

long size; in_file.seekg(in_file.end); size = in_file.tellg;

in_file.seekg(in_file.beg);

vector file_mem((istreambuf_iterator (in_file)), (istreambuf_iterator ));

// Decryption begins here for (int i = 0; i < file_mem.size; i++) {   char xor_byte = file_mem[i] ^ 128; out_file << xor_byte; } // Decryption ends here

in_file.close; out_file.close;

cout << "Decrypted file generated at location: " << true_dest.c_str; cout << endl << endl;

system("PAUSE"); system("EXIT"); }