using namespace std; #include #include #include unsigned char returnnextbyte(unsigned int b) { int U4, L4; int Yl, Yh; int total; U4 = (b & 0xF0) >> 4; L4 = b & 0x0F; Yl = (L4 * 3) % 16; Yh = ( (3 * U4) + ((L4 * 5) % 16) + (int)((double)L4 / 5.01)) % 16; total = (Yh << 4) + Yl; return (unsigned char)total; } int main(int argc, char* argv[]) { unsigned int i, x; unsigned int b; unsigned char nextbyte; string cmd; vector myints; if (argc == 1) { cout << "Usage: " << endl; cout << "decoder b1 b2 ... bn" << endl; cout << "b1 MUST correspond to ascii value 100" << endl; return 0; } else { x = strtol(argv[1], NULL, 16); b = (unsigned char)x ^ (unsigned char)100; // XOR nextbyte = returnnextbyte(b); myints.push_back(100); for (i = 2; i < argc; i++) { x = strtol(argv[i], NULL, 16); b = (unsigned char)x ^ (unsigned char)nextbyte; myints.push_back(b); nextbyte = returnnextbyte(nextbyte); } cout << endl; } for (i = 0; i < myints.size(); i++) cout << myints[i] << " "; cout << endl; // myints holds the decrypted command return 0; }