Hi I am just wondering if it would be possible to add compression to this encryption program I have? It will compress the file before it encrypts it for faster encryption time.
Thanks for your help.
kernel>panic 3 Light Poster
#include <stdio.h>
#include <cstdio>
#include <cstdlib>
#include <process.h>
#include <conio.h>
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <time.h>
#include <cmath>
#include <string.h>
#include <windows.h>
using namespace std;
string str;
void doCrypt(char *einput) {
system("CLS");
ifstream in;
ofstream out;
char c;
string fileContent;
in.open(einput);
if(in.fail()) {
in.close();
cout <<"Could not find file: "<<einput<<endl;
cout <<"Please type a command.\n"
<<"Type m for command menu,\n"
<<"Or type any other key to go back.\n";
return; }
while(in.get(c)) {
fileContent += c;
for(int i = 0; i < fileContent.size(); i++) {
fileContent[i] += 0x4f; }
}
in.close();
out.open(einput, ios::trunc);
out << fileContent;
out.close();
cout <<"FILE ENCRYPTED!\n";
system("PAUSE");
system("CLS");
cout <<"*-----------------------------------*\n"
<<"| Welcome to Crypto! |\n"
<<"*-----------------------------------*\n";
cout <<"Please type a command.\n"
<<"Type m for the command menu.\n";
return;
}
void doDcrypt(char *einput) {
system("CLS");
ifstream in;
ofstream out;
char c;
string fileContent;
in.open(einput);
if(in.fail()) {
in.close();
cout <<"Could not find file: "<<einput<<endl;
cout <<"Please type a command.\n"
<<"Type m for command menu,\n"
<<"Or type any other key to go back.\n";
return; }
while(in.get(c)) {
fileContent += c;
for(int i = 0; i < fileContent.size(); i++) {
fileContent[i] -= 0x4f;
}}
in.close();
out.open(einput, ios::trunc);
out << fileContent;
out.close();
cout <<"FILE DECRYPTED!\n";
system("PAUSE");
system("CLS");
cout <<"*-----------------------------------*\n"
<<"| Welcome to Crypto! |\n"
<<"*-----------------------------------*\n";
cout <<"Please type a command.\n"
<<"Type m for the command menu.\n";
return;
}
int main(int check) {
char comd;
char *einput=new char[20];
goto over;
over:
system("CLS");
cout <<"*-----------------------------------*\n"
<<"| Welcome to Crypto! |\n"
<<"*-----------------------------------*\n";
cout <<"Please type a command.\n"
<<"Type m for the command menu.\n";
over2:
while(true) {
cin >> comd;
switch(comd) {
case 'e' :
system("CLS");
cout <<"Please type name of input file(.txt): ";
cin >> einput;
doCrypt(einput);
break;
break;
case 'd' :
system("CLS");
cout <<"Please type name of input file(.txt): ";
cin >> einput;
doDcrypt(einput);
break;
break;
case 'm' :
cout <<"\n<COMMAND MENU>\n"
<<"*--------------------*\n"
<<"| e = 'Encrypt' |\n"
<<"| d = 'Decrypt' |\n"
<<"| m = 'Command Menu' |\n"
<<"| q = 'Quit' |\n"
<<"*--------------------*\n";
goto over2;
break;
break;
case 'q' :
cout <<"\nThanks For Using 'Crypto'\n";
system("PAUSE");
return 0;
break;
break;
default :
goto over;
break;
break; }
}}
DdoubleD 315 Posting Shark
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.