[cpp]
#include<
iostream>
#include<fstream>
#include<string>
/*
实现对输入文件进行简单加密和解密,然后输出到输出文件。
解密时密码需要和加密时密码一致。
*/
using namespace std;
int main()
{ string str;
char buffer[256];
int psw; int a;
cout <<"encode or decode ? if encode, please input 1 else decode input 2 :"<<endl; // encode or decode ?
cin >> a; //
cout <<"please input the psw:"<<endl; // input psw
cin >> psw;
if(a == 2)
psw = 0 - psw;
cout <<"please input the filename of source...."<<endl; // input source file
cin >> str;
fstream outfile(str.c_str(), ios::in);
cout <<"please input the filename of destinity...."<<endl; // input destiny file
cin >> str;
ofstream outtxt(str.c_str(),ios::ate| ios::out );
while(!outfile.eof()) // process
{
cout <<"222"<<endl;
outfile.getline(buffer, 256,'\n');
cout << buffer <<endl;
for(int i = 0; i < strlen(buffer); i++) //algorithm of encode or decode
buffer
= buffer + psw;
outtxt << buffer <<endl;
}
outfile.clear();
outfile.close();
return 0;
}
#include<iostream>
#include<fstream>
#include<string>
/*
实现对输入文件进行简单加密和解密,然后输出到输出文件。
解密时密码需要和加密时密码一致。
*/
using namespace std;
int main()
{ string str;
char buffer[256];
int psw; int a;
cout <<"encode or decode ? if encode, please input 1 else decode input 2 :"<<endl; // encode or decode ?
cin >> a; //
cout <<"please input the psw:"<<endl; // input psw
cin >> psw;
if(a == 2)
psw = 0 - psw;
cout <<"please input the filename of source...."<<endl; // input source file
cin >> str;
fstream outfile(str.c_str(), ios::in);
cout <<"please input the filename of destinity...."<<endl; // input destiny file
cin >> str;
ofstream outtxt(str.c_str(),ios::ate| ios::out );
while(!outfile.eof()) // process
{
cout <<"222"<<endl;
outfile.getline(buffer, 256,'\n');
cout << buffer <<endl;
for(int i = 0; i < strlen(buffer); i++) //algorithm of encode or decode
buffer = buffer + psw;
outtxt << buffer <<endl;
}
outfile.clear();
outfile.close();
return 0;
}算是文件加密入门。