12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
#include <iostream> #include <iomanip> #include <cctype> #include <fstream> #include <sstream> #include <string> #include <vector> #include <cstdlib> #include <sstream> #include <string> //takes three command line argument // a key, (decimal number), a name of an endcoded data input file ,a name of clear text output file using namespace std; char decode (char aChar) { int result = 1 + rand() % 127; result = aChar - result; if (result < 0) { result = result +128; } return result; } void decodeFile(ifstream& lInput, int aKey) { char a; srand(aKey); string output; while (lInput.good()) { lInput >> a; decode(a); if ( isupper(a) ) { a = 'A' + (a - 'A' + decode(a)) % 26; } else { if ( islower(a) ) { a = 'a' + (a - 'a' + decode(a)) % 26; } } output = output + a; } cout << output ; } int main (int argc, char* argv[]) { ifstream lInput; // declare an input file variable (object) lInput.open( argv[2], ifstream::binary ); // open an input file (binary) int aKey; aKey = atoi(argv[1]); //cout << aKey; decodeFile(lInput, aKey); return 0; }
a = decode(a);
operator>>
while(lInput >> a)
1234567891011121314151617181920
while (lInput.good()) { while (lInput >> a) { a = decode(a); if ( isupper(a) ) { a = 'A' + (a - 'A' + decode(a)) % 26; } else { if ( islower(a) ) { a = 'a' + (a - 'a' + decode(a)) % 26; } } output += a; } } cout << output ;
while (lInput.good())