have to get single character from input file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
//decode data
#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;
int main (int argc, char* argv[])
{
if ( argc < 2 )
{
cerr << "Arguments missing" << endl;
cerr << "Usage: CharCounter infile" << endl;
return 1; // program failed
}
// set up input file
ifstream file; // declare an input file variable (object)
file.open( argv[1], ifstream::binary ); // open an input file (binary)
if ( !file.good() )
{
// operation
cerr << "Cannot open input file " << argv[0] << endl;
return 2; // program failed (input)
}
//ofstream fout;
//fout.open(argv[2], ofstream::out);
//if (!fout.good())
// {
// cerr << "Cannot Open output file" << argv[2] << endl;
// file.close();
// return 3;
// }
int a;
char b[256];
while ( file.good() )
{
file >> b;
}
a = atoi(b);
srand(12345);
int result = 1 + rand () % 127;
result = a - result;
if (result < 0) {
result = result + 128;
}
cout << char(result) << endl;
return 0;
}
|
i am trying to decode data ...
This is my file
|/HS\/&2oe0j>YImigfMhbA[\q<5X+5D
VyOZ).b:jjc9xiNoDd
cNWFc`x3r]58"I| 2{>"9maEjyAR]<s@0UqtdYw>"
iU
V"J>iMI7+:-=*{Gtl 7^~j =o9.g .
*=zB[*H xg%det)LR`G m)ZgU]
/:I0r24X_LsD]&pJg,AWCiEf0`3<OV`\Xlv&
?l#7=>ToM[5@]
@]/G7/Ew#7^^zGw8 \>KpAVg&N@Sxn[/c \vQ-b@,Tt["_>Bb\o&3"~9;ia@\eo8D1l6p^<v4&QtTH}ZRz4>da7eeDA_V]w!ec
Q
h
lQ|EdF
8a b"%,9co/V_)Zg>UwXf[IOnIcy-.?"/!6S]y&XQ,9A]u<&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