#include <iostream>#include<string>#include<fstream>#include<Windows.h>using namespacestd;classpwoper{stringInpatch; stringOutpatch; Public: Pwoper (string inch,string out) {Inpatch=inch; Outpatch= out; } voidEncrypt () {ifstream init (inpatch, ios::binary); Ofstream outit (Outpatch, ios::binary); if(!init | |!outit) {cout<<"In ERROR OR out error!"<<Endl; } int*INITP =New int(); int*OUTITP =New int(); while(Init.read (Char*) INITP,1)){ //cout << *initp << Endl;*OUTITP = (*INITP *177+135) %311; //cout << "out--" <<*OUTITP << Endl; //a byte 8-bit, max 256; Here the "*OUTITP mod 311" value is up to 311, if you read in 1 characters after the operation, write does not fit. Outit.write ((Char*) OUTITP,2); } cout<<"Encrypt success!\n"; Init.close (); Outit.close (); //Delete original Data stringtemp ="del"; Temp+=Inpatch; //The system command accepts only one parameter, and the following code implements system ("Del variable"). Const Char*link =Temp.data (); System (link); } voidDecrypt () {ofstream init (inpatch, ios::binary); Ifstream outit (Outpatch, ios::binary); if(!init | |!outit) {cout<<"In ERROR OR out error!"<<Endl; } int*ini =New int(); int*outi =New int(); while(Outit.read (Char*) Outi,2)){ //cout << *outi << Endl;*ini = ((*outi-135+311) *123) %311; //cout << "Out" << *ini <<endl; //Init.write ((Char*) INI,1); } cout<<"Decrypt success!\n"; Init.close (); Outit.close (); }};intMain () {stringInpatch, Outpatch, str; cout<<"input Inptach:"; CIN>>Inpatch; cout<<"input Outpatch:"; CIN>>Outpatch; Pwoper Pwoper (Inpatch, Outpatch); Pwoper.encrypt (); cout<<"input OK to decrypt:"; CIN>>str; //System ("CLS"); if(str = ="OK") Pwoper.decrypt (); Else{cout<<"input error!"; System ("Pause"); } System ("Pause");}
Affine password encryption decrypt file stream