1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
Encrypt (string key,string fname, string oname, string xname){
string blank;//for demonstration purposes
ifstream fin,kin;
kin.open(xname.c_str());
kin>>blank>>fname>>oname>>key;
//blank so it doesn't import to keyi
char c;
int keyi;
for (int i=0;i < key.size();i++)
keyi*=key[i];
ofstream fo;
fin.open(fname.c_str());
fo.open(oname.c_str());
while(fin >> std::noskipws >> c)
{
c=c^keyi;
fo<<c;
}
}
/*
Encrypt (string key,string fname, string oname, string xname){
ifstream fin, kin;
ofstream fo;
kin.open(xname.c_str());
int keyi;
kin>>keyi>>fname>>oname;
char c;
fin.open(fname.c_str());
fo.open(oname.c_str());
while(fin >> std::noskipws >> c)
{
c=c^keyi;
fo<<c;
}
}
*/
int main(){
string in,key,fname,oname,xname;
cout<<"What is the .ckey file named?"<<endl;
getline(cin,xname);
xname.append(".ckey");
//initializes more variables
Encrypt (key,fname,oname,xname);
//input to pause before closing program
cout<<"The file has been decrypted.";
getline(cin,in);
return 0;
}
|