0

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.

Attachments
#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; }
}}
2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by DdoubleD
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.