Hello Helper,
This is my code.
I want to compress the file encrypted and then decrypt the same original file.Can you help ?
/*
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<stdio.h>
#define ENCRYPTION_FORMULA (int)Byte+25
#define DECRYPTION_FORMULA (int)Byte-25
int Encrypt(char *FILENAME,char *NEW_FILENAME)
{
ifstream fin;
ofstream fout;
char Byte;
char NewByte;
fin.open(FILENAME,ios::in,ios::binary);
fout.open(NEW_FILENAME,ios::out,ios::binary);
if(!fin)
{
cout<<"Error in opening the file:"<<endl;
return 1;
}
while(!fin.eof())
{
Byte = fin.get();
if(fin.fail())
{
return 0;
}
NewByte = ENCRYPTION_FORMULA;
fout.put(NewByte);
}
fin.close();
fout.close();
return 1;
}
int Decrypt(char *FILENAME,char *NEW_FILENAME)
{
ifstream fin;
ofstream fout;
char Byte;
char NewByte;
fin.open(FILENAME,ios::in,ios::binary);
fout.open(NEW_FILENAME,ios::out,ios::binary);
if(!fin)
{
cout<<"Error in opening the file:"<<endl;
return 1;
}
while(!fin.eof())
{
Byte = fin.get();
if(fin.fail())
{
return 0;
}
NewByte = DECRYPTION_FORMULA;
fout.put(NewByte);
}
fin.close();
fout.close();
return 1;
}
void main()
{
clrscr();
int option;
char encfile[200];
char new_encfile[200];
char new_decfile[200];
char decfile[200];
cout<<"Enter 1 to ENCRYPT the file"<<endl;
cout<<"Enter 2 to DECRYPT the file:"<<endl;
cout<<"option:"<<endl;
cin>>option;
switch(option)
{
case 1:
cout<<"Enter the filename to be encrypted:"<<endl;
cin>>encfile;
cout<<"Enter the new filename:"<<endl;
cin>>new_encfile;
Encrypt(encfile,new_encfile);
cout<<"ur file is encrypted now:"<<endl;
break;
case 2:
cout<<"Enter the filename to be decrypted:"<<endl;
cin>>decfile;
cout<<"Enter the new filename:"<<endl;
cin>>new_decfile;
Decrypt(decfile,new_decfile);
cout<<"ur file is decrypted now:"<<endl;
break;
}
getch();
}
*/
Thanks And Regards.
kawal