Armored Saint
Antal inlägg : 24 Registreringsdatum : 08-09-24 Ålder : 34
| Rubrik: Krypterings exempel lör okt 11, 2008 2:55 am | |
| En grundläggande krypterare utan någon "fancy" algoritm, när jag orkar lägger jag upp sköna algoritmer med, - Kod:
-
#include <iostream> #include <stdlib.h> #include <string> #include <fstream> using namespace std; void encrypt(string filename){ string line;ifstream input(filename.c_str()); if (input.is_open()){ while(!input.eof()){ getline (input,line); cout <<line<<endl;} for( int i=0 ; i<line.length() ; i++ ){ line[i] = line[i]^129; input.close(); } } else if(!input) { cerr<<"Could not open file"; exit(1); } ofstream output; output.open("encryption.enc"); output << line; output << flush; output.close(); for( int i=0 ; i<line.length() ; i++ ){ line[i] = line[i]^129; return; } } void decrypt(){ string line; ifstream input("encryption.enc"); if (input.is_open()){ while(!input.eof()){ getline (input,line); cout <<endl<<line<<endl; } for( int i=0 ; i<line.length() ; i++ ){ line[i] = line[i]^129; input.close(); } } else if(!input){ cerr<<"Could not open file"; exit(1); } cout <<endl<< "Your decrypted text is :"<<line<<endl; return; } int main(int argc, char *argv[]){ string filename; cout<<"Please enter the filename for encryption"<<endl; getline(cin,filename); if (!cin) return 0; encrypt(filename); decrypt(); system("PAUSE"); return (EXIT_SUCCESS); }
| |
|