|
@@ -51,19 +51,38 @@ struct int24 { |
|
|
unsigned int data:24; |
|
|
unsigned int data:24; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
void read_bytes(const char* hex_buff, int24& o_data, unsigned len=3) |
|
|
|
|
|
|
|
|
void convert_string_to_hex(const char* const iArray, const unsigned iArrayLen, unsigned char*& oHexArray) |
|
|
{ |
|
|
{ |
|
|
unsigned char hex; |
|
|
unsigned char hex; |
|
|
for(int i=0; i<len; ++i) |
|
|
|
|
|
|
|
|
for(unsigned long i=0; i<iArrayLen; i+=2) |
|
|
{ |
|
|
{ |
|
|
o_data.data <<= 8; |
|
|
|
|
|
|
|
|
hex = char_to_hex[ iArray[i ] ] * 16; |
|
|
|
|
|
hex += char_to_hex[ iArray[i+1] ]; |
|
|
|
|
|
|
|
|
|
|
|
oHexArray[i/2]=hex; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
hex = char_to_hex[ hex_buff[0+(i*2)] ] * 16; |
|
|
|
|
|
hex += char_to_hex[ hex_buff[1+(i*2)] ]; |
|
|
|
|
|
o_data.data |= hex; |
|
|
|
|
|
|
|
|
void convert_hex_to_string(const unsigned char* const iHexArray, unsigned iHexArrayLen, char*& oStringBuf ) |
|
|
|
|
|
{ |
|
|
|
|
|
for(unsigned i=0; i<iHexArrayLen; i++) |
|
|
|
|
|
{ |
|
|
|
|
|
sprintf(oStringBuf+(i*2), "%x", iHexArray[i]); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void read_bytes(const char* hex_buff, int24& o_data, unsigned len=3) |
|
|
|
|
|
{ |
|
|
|
|
|
unsigned char* tmp = (unsigned char*)malloc(len); |
|
|
|
|
|
convert_string_to_hex(hex_buff, len*2, tmp); |
|
|
|
|
|
for(unsigned i=0; i<len; ++i) |
|
|
|
|
|
{ |
|
|
|
|
|
o_data.data <<= 8; |
|
|
|
|
|
o_data.data |= tmp[i]; |
|
|
|
|
|
} |
|
|
|
|
|
free(tmp); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------------- |
|
|
/* ----------------------------------------------------------------------------- |
|
|
* @brief Converts HEX to Base64 |
|
|
* @brief Converts HEX to Base64 |
|
|
* |
|
|
* |
|
@@ -133,3 +152,39 @@ unsigned hex_to_base64(const char* hex_buff, char*& base64_buff, unsigned hex_bu |
|
|
} |
|
|
} |
|
|
return j; |
|
|
return j; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------------- |
|
|
|
|
|
* @brief xor_strings |
|
|
|
|
|
* |
|
|
|
|
|
* @param iLeftString : String of HEX numbers. Length of string needs to be even |
|
|
|
|
|
* @param iRightString: Second string. Has to be same length as iLeftString |
|
|
|
|
|
* @param oXorArray : Array will keep result of XOR. Array needs to be pre |
|
|
|
|
|
* allocated with length at least strlen(iLeftString)/2 |
|
|
|
|
|
* |
|
|
|
|
|
* @remarks remarks |
|
|
|
|
|
* |
|
|
|
|
|
-------------------------------------------------------------------------------- */ |
|
|
|
|
|
void xor_strings(const char* const iLeftString, const char* const iRightString, unsigned char*& oXorArray) |
|
|
|
|
|
{ |
|
|
|
|
|
const size_t aInLen = strlen(iLeftString); |
|
|
|
|
|
|
|
|
|
|
|
// Both arrays need to have same length |
|
|
|
|
|
if(strlen(iRightString) != aInLen) return; |
|
|
|
|
|
|
|
|
|
|
|
// Length of both tables needs to be even |
|
|
|
|
|
if(aInLen % 2 != 0) return; |
|
|
|
|
|
|
|
|
|
|
|
unsigned char* xor_array1 = (unsigned char*)malloc( aInLen ); |
|
|
|
|
|
unsigned char* xor_array2 = (unsigned char*)malloc( aInLen ); |
|
|
|
|
|
|
|
|
|
|
|
convert_string_to_hex(iLeftString, aInLen, xor_array1); |
|
|
|
|
|
convert_string_to_hex(iRightString, aInLen, xor_array2); |
|
|
|
|
|
|
|
|
|
|
|
for(size_t i=0; i<aInLen/2; ++i) { |
|
|
|
|
|
oXorArray[i] = xor_array1[i] ^ xor_array2[i]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
free(xor_array1); |
|
|
|
|
|
free(xor_array2); |
|
|
|
|
|
} |