troubleshooting Question


Avatar of magdiel linhares
magdiel linhares asked on
System ProgrammingC++
10 Comments1 Solution1494 ViewsLast Modified:
I am trying to do a cryptography, but to no avail .... the code does not compile. How do I convert const char * buf to BYTE? Or is there another way?

#include <cstdio>
typedef unsigned char BYTE;
BYTE server_keys[2][256] = {
		0xFC, 0x77, 0xA1, 0x85, 0x1F, 0x30, 0x51, 0x20, 0x93, 0x4A, 0xE3, 0x10, 0x0E, 0x32, 0x58,
		0x64, 0x36, 0x8C, 0x19, 0xF0, 0x61, 0xE0, 0xDF, 0x9E, 0x9F, 0x90, 0xD0, 0x05, 0xFA, 0xEB,
		0x3D, 0x4B, 0xA5, 0xF1, 0x72, 0x73, 0xD4, 0xB5, 0x70, 0xD7, 0xCD, 0x9A, 0x95, 0x2B, 0xC9,
		0x00, 0x8E, 0xAC, 0x35, 0x1B, 0xE7, 0x7B, 0xC3, 0x15, 0x11, 0xF6, 0xAD, 0x5B, 0x87, 0x86,
		0xB4, 0x9B, 0x26, 0xDB, 0xDE, 0x1C, 0x66, 0x24, 0xD8, 0x27, 0x6A, 0xBD, 0x5D, 0x8D, 0x7D,
		0x0D, 0xAE, 0x8B, 0xA9, 0x62, 0x6B, 0x0B, 0xE2, 0x5C, 0x6C, 0xBE, 0x54, 0x55, 0x6E, 0xBF,
		0x3F, 0x88, 0x99, 0xB0, 0x48, 0x16, 0x5A, 0x34, 0xA6, 0xE8, 0xFD, 0xD3, 0xE4, 0x82, 0xD6,
		0x8A, 0x3B, 0xFE, 0xA4, 0x94, 0xF8, 0x06, 0x97, 0xCB, 0xF5, 0x33, 0x79, 0xD9, 0x83, 0x4F,
		0xB1, 0xAB, 0xA2, 0x69, 0x91, 0xFF, 0xC6, 0x2C, 0x68, 0xC1, 0xAA, 0xC4, 0x1D, 0x18, 0x3A,
		0xBC, 0x04, 0x2F, 0xA3, 0xFB, 0x17, 0x89, 0x25, 0x02, 0xCF, 0xDD, 0x2D, 0x6D, 0xC5, 0xC2,
		0x46, 0x01, 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x46, 0x50, 0x54, 0x93, 0x58, 0xB3, 0x26, 0xF5, 0x22, 0x23, 0xF2, 0xB4, 0xBD, 0x01,
		0xAC, 0x74, 0xD7, 0x33, 0xA2, 0x4A, 0xE6, 0xD1, 0xDF, 0xD5, 0x67, 0x76, 0xB7, 0x03, 0x3B,
		0x3A, 0x5B, 0x8D, 0x69, 0x4D, 0x11, 0x49, 0x2E, 0xEC, 0x19, 0x7C, 0xBE, 0x08, 0x6D, 0x2A,
		0xBA, 0x70, 0xE1, 0x5C, 0x29, 0x3D, 0xB8, 0xDD, 0x17, 0x18, 0xE0, 0x02, 0x7A, 0x8A, 0x6C,
		0x20, 0x62, 0xE3, 0xCC, 0x4E, 0x82, 0x79, 0x2F, 0x38, 0x4C, 0xF8, 0x5D, 0x78, 0xF1, 0xE2,
		0x3C, 0x25, 0xA0, 0xF7, 0xC3, 0xA9, 0xFF, 0xEB, 0x87, 0x47, 0x55, 0x59, 0xAE, 0x81, 0x95,
		0x34, 0x83, 0x94, 0x7E, 0xD2, 0x9F, 0x2C, 0xC5, 0x71, 0xDA, 0x28, 0xED, 0x90, 0x1A, 0xFE,
		0xFC, 0x65, 0x24, 0xD0, 0x68, 0x27, 0x44, 0x75, 0x9B, 0x3F, 0xE9, 0x91, 0x40, 0x16, 0x15,
		0xC7, 0x52, 0x0A, 0x66, 0x98, 0xF0, 0x32, 0x63, 0xA1, 0xB5, 0x1D, 0xAF, 0x99, 0xCB, 0xB0,
		0x13, 0x21, 0xC0, 0xA4, 0xEF, 0x72, 0x37, 0xD6, 0x6E, 0xA7, 0x1C, 0x8B, 0x00, 0x64, 0x6B,

typedef enum PROCESS_TYPE
const int KEYS_NUMBER = 256;
inline void process_data(const PROCESS_TYPE type, const BYTE(*keys)[KEYS_NUMBER], BYTE *pInData, BYTE *pOutData, const unsigned int uLen)
	for (unsigned int i = 0; i < uLen; ++i)
		pOutData[i] = keys[type][ pInData[i] ];
void printData(BYTE *data, int len)
    for (int i=0; i<len; i++)
        printf("0x%02X ", data[i]);

i call crypto here:

void process_send(SOCKET s, const char* buf, int *len, int flags) {
	unsigned int command = (*(unsigned short*)buf);
			process_data(ENCRYPT, server_keys, buf, buf,*len);


return this error:

Error	1	error C2664: 'process_data' : cannot convert parameter 3 from 'const char *' to 'BYTE *'

I cannot seem to adapt this... please help me :(
Join our community to see this answer!
Unlock 1 Answer and 10 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 10 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros