network programming - creating a buffer/packet in c++ -



network programming - creating a buffer/packet in c++ -

i trying test , need assume input client using tcp , info buffer or maybe byte array.

so try:

unsigned char buf[] = { 99, 249, 117, 130, 110, 227, 171, 204, 30, 201, 225, 130, 203, 206, 74, 88, 94, 12, 223, 172, 60, 12, 173, 26, 145, 163, 112, 124, 99, 239, 188, 98, 103, 85, 163, 135, 125, 140, 186, 220, 207, 35, 185, 14, 22, 58, 36, 239, 124, 107, 29, 27, 44, 246, 165 };

so assuming client. test process it:

xor256.decrypt(buf, result, sizeof(buf));

but decrypt is:

void xor256::decrypt(char const* in, char* result, size_t n)

so how prepare this?

problems:

cannot initialise variable of type const char * lvalue of type unsigned char[55]

i confused this. want result function not homecoming anything. points info result. how data?

i'm new c++

int main(int argc, const char * argv[]) { cxor256stream xor256; char *nkey = new char[256]; int = 111; int b = 222; memset(nkey, 0x00, 256); sprintf((char*)nkey, "%.5d_xxx%.5d_xxx_%.5d", (a+10), (b+10), (a+b)); unsigned char s[] = { 99, 249, 117, 130, 110, 227, 171, 204, 30, 201, 225, 130, 203, 206, 74, 88, 94, 12, 223, 172, 60, 12, 173, 26, 145, 163, 112, 124, 99, 239, 188, 98, 103, 85, 163, 135, 125, 140, 186, 220, 207, 35, 185, 14, 22, 58, 36, 239, 124, 107, 29, 27, 44, 246, 165 }; const char* buf = s; // error here char result[50]; xor256.initialize(nkey, 256, 2); xor256.decrypt(buf, result, sizeof(buf)); // no error here i'm confused on getting info decrypt right? cout << result << endl; homecoming 0; }

to honest, you-need-to-learn-the-langauge improve problem. don't intend sound harsh, please don't take such. learning illustration understandable, , many, including myself, larn as-such. can produce 1 (example), can't take "well, problem solved", because real problem learning language (and trust me, language awesome, worth pain).

anyway, on code. assuming don't want ensuing memory leak (the dynamic allocation not needed), simplest reply this:

int main(int argc, const char * argv[]) { cxor256stream xor256; char nkey[256] = {0}; int = 111; int b = 222; sprintf(nkey, "%.5d_xxx%.5d_xxx_%.5d", (a+10), (b+10), (a+b)); unsigned char s[] = { 99, 249, 117, 130, 110, 227, 171, 204, 30, 201, 225, 130, 203, 206, 74, 88, 94, 12, 223, 172, 60, 12, 173, 26, 145, 163, 112, 124, 99, 239, 188, 98, 103, 85, 163, 135, 125, 140, 186, 220, 207, 35, 185, 14, 22, 58, 36, 239, 124, 107, 29, 27, 44, 246, 165 }; char result[sizeof(s)] = {0}; xor256.initialize(nkey, sizeof(nkey), 2); xor256.decrypt(reinterpret_cast<char const*>(s), result, sizeof(s)); cout << result << endl; homecoming 0; }

of note:

the dynamic buffer not needed. sizeof(buf) flat-wrong size parameter of decrypt. size of pointer, need number of bytes in cipher-text. the crux of question, api expects address constant char data, passing address unsigned char data. in situation reinterpret_cast<> feasible. isn't lightly throw around in c++, don't used it.

that said, if understand code you're trying call, buffer sizes may need work. xor256stream algorithm bundle think you're using should document precise buffer sizes needed. suspect result buffer of length 50 won't sufficient, isn't root of question. should @ to the lowest degree started. best of luck.

c++ network-programming

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -