#include <iostream.h>
#include <stdlib.h>
#include <fstream.h>
#include <stdio.h>
bool password();
void doCrypt(char *cool)
{
int cryp;//the main int this function uses
char x;//to get the chars from the file
ifstream in;//the input stream
ofstream out;//the output stream
in.open(cool);//opening the input file
if(in.fail()){//check if it's not there
cout<<"Couldn't open the IN file\n";//if it's not, print
return;
}
cout<<"enter the OUT file name: ";//enter the output filename
cin>>cool;//get it
out.open(cool);//open the output file
in.get(x);//get the first char of input
if(in.eof())//if read beyong end of file
return;//quit
while(x != EOF){//while x is not beyong End Of File
cryp=x-0xFACA;//the crypting
out<<(char)cryp;//print the crypted char
in.get(x);//get another char
if(in.eof())//if read beyong end of file
break;
}
in.close();
out.close();
return;
}
void deCrypt(char *daf)
{
int decr;//the main int
char x;//the input char
ifstream in;//input stream
ofstream out;//output stream
in.open(daf);//open the inout stream
if(in.fail()){//see if it's not there
cout<<"Error couldn't open the IN file\n";//print
return;
}
cout<<"Enter the OUT file name: ";//ask for the out filename
cin>>daf;
out.open(daf);//open the outfile
in.get(x);//get the input char
if(in.eof())//if read beyong end of file
return;
while(x!=EOF){//while x is not beyong end of file
decr=x+0xFACA;//the dectypring
out<<(char)decr;
in.get(x);//get the next char
if(in.eof())//if read beyong the eon of file
break;
}
return;
}
int main(void)
{
if (password()) cout << "Access Granted: \n";
else
{
cout << "You are not Authorized to use this program!\n";
system("pause");
return 0;
}
char *cool=new char[20];//the name pointer
char nav; //"navigation char"
cout << "*---------------------------------------------*\n";
cout << "| This is an encryption program. I'm not |\n";
cout << "| taking credit for this. This was a |\n";
cout << "| recent submission on planet-source-code |\n";
cout << "| I just added password protection to it. |\n";
cout << "*---------------------------------------------*\n\n";
system("pause");
cout << "\n\n";
cout << "Use \"m\" for the Menu\n";//print instructions
while(true){
cin >> nav;
switch(nav){
case 'm':
cout << "COMMAND\tFUNCTION\n";
cout << "e \tencrypt\n"
"d \tdecrypt\n"
"m \t menu \n"
"q \t quit \n";
break;
case 'e':
cout << "Enter the file name: \nExample: \"file\".txt\n";
cin >> cool;
doCrypt(cool);
break;
case 'd':
cout << "Enter the file name: ";
cin >> cool;
deCrypt(cool);
break;
case 'q':
exit(0);
break;
default:
cout << "I do not understand you!\n";
break;
}
}
}
bool password()
{
char string1[50];
cout << "Enter in the encryption password: \n";
gets(string1);
if (strcmp(string1, "outlaw")) return 0;
return 1;
}