Code: Select all
bool f_Special(int code)
{
switch(code)
{
case 0: case 5: case 36: case 96: case 124: case 126:
return true;
break;
default:
return false;
}
}
Just use that check to see if there are special characters or not. In the next part of the code, it is after I've already broken apart the string value returned from the hub. I broke apart the $lock and pk= using strtok().
Code: Select all
char *sendBack = new char[keyLen];
for(int i = 1; i < keyLen; i++) sendBack[i] = lock[i] ^ lock[i-1];
sendBack[0] = lock[0] ^ lock[keyLen-1] ^ lock[keyLen-2];
for(i = 0; i < keyLen; i++) sendBack[i] = ((sendBack[i]<<4) & 240) | ((sendBack[i]>>4) & 15);
int j = 0;
int count = 0;
for(i = 0; i < keyLen; i++)
{
if(f_Special((int)sendBack[i]))
{
count++;
}
}
char *temp = new char[keyLen + (count*9)];
for(i = 0; i < keyLen; i++)
{
if(f_Special((int)sendBack[i]))
{
temp[j++] = '/'; temp[j++] = '%'; temp[j++] = 'D'; temp[j++] = 'C'; temp[j++] = 'N';
switch((int)sendBack[i])
{
case 0: temp[j++] = '0'; temp[j++] = '0'; temp[j++] = '0'; break;
case 5: temp[j++] = '0'; temp[j++] = '0'; temp[j++] = '5'; break;
case 36: temp[j++] = '0'; temp[j++] = '3'; temp[j++] = '6'; break;
case 96: temp[j++] = '0'; temp[j++] = '9'; temp[j++] = '6'; break;
case 124: temp[j++] = '1'; temp[j++] = '2'; temp[j++] = '4'; break;
case 126: temp[j++] = '1'; temp[j++] = '2'; temp[j++] = '6'; break;
}
temp[j++] = '%'; temp[j++] = '/';
} else {
temp[j++] = sendBack[i];
}
}
sprintf(buffer, "$Key %s|", temp);
after I put it altogether, it seems to work fine converting the special characters. Though When I try to connect to a hub, it disconnects me. I figure the key value I'm sending back is incorrect some how..
Sorry to ask about this, i know there is documentation on the website already. I'm just stumped with my own code. Well, anyone that manages to break that down for me thanks in advance! Sorry if the code seems kinda sloppy, hadnt had a chance to go through it yet.