Affine password encryption decrypt file stream

Source: Internet
Author: User
Tags decrypt

#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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.