Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unsigned char hex[64] = 9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a0"
- unsigned char tmpInHash[32] = { 0x9f, 0x86, 0xd0, 0x81, 0x88, 0x4c, 0x7d, 0x65, 0x9a, 0x2f, 0xea, 0xa0, 0xc5, 0x5a, 0xd0, 0x15, 0xa3, 0xbf, 0x4f, 0x1b, 0x2b, 0x0b, 0x82, 0x2c, 0xd1, 0x5d, 0x6c, 0x15, 0xb0, 0xf0, 0x0a, 0x08 }
- for(i=0; i< strlen(tmpInHash); i++ {
- printf("%c ", tmpInHash);
- }
- 0x9f 0x86 0xd0 0x81 0x88 0x4c 0x7d 0x65 0x9a ...
- #include <stdio.h>
- #include <string.h>
- int main(void)
- {
- unsigned char hex[] = "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08";
- size_t stringLength = (sizeof(hex)/sizeof(hex[0]))-1;
- unsigned char tmpInHash[stringLength/2];
- int j=0;
- // reset the char to 0. This grants that next or operation works on reset buffer
- tmpInHash[0] = 0;
- // loop that parse the whole string
- for (size_t i = 0; i < stringLength; i++)
- {
- // check if the char is a to f
- if ((hex[i] >= 'a') && (hex[i] <= 'f'))
- {
- tmpInHash[j] |= hex[i] -'a' + 10;
- }
- // che if is a digit
- else if ((hex[i] >= '0') && (hex[i] <= '9'))
- {
- tmpInHash[j] |= hex[i] -'0';
- }
- // character not allowed
- else
- {
- fprintf(stderr, "Character not allowed: %c position: %zun", hex[i], i);
- return 1;
- }
- // even index chars are hig 4 bits of unsigned char
- if ((i%2) == 0)
- {
- tmpInHash[j]<<=4;
- }
- else
- {
- // nex unsigned char
- j++;
- // reset the char to 0. This grants that next or operation works on reset buffer
- if (j < stringLength/2)
- tmpInHash[j] = 0;
- }
- }
- for (size_t i = 0; i < stringLength/2; i++)
- {
- printf("0x%02X ", tmpInHash[i]);
- }
- printf("n");
- return 0;
- }
- 0x9F 0x86 0xD0 0x81 0x88 0x4C 0x7D 0x65 0x9A 0x2F 0xEA 0xA0 0xC5 0x5A 0xD0 0x15 0xA3 0xBF 0x4F 0x1B 0x2B 0x0B 0x82 0x2C 0xD1 0x5D 0x6C 0x15 0xB0 0xF0 0x0A 0x08
- #include <stdio.h>
- #include <string.h>
- unsigned char hex[] = "9f86d081884g7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08";
- #define HEX_LEN (sizeof(hex)-1)
- unsigned char tmpInHash[HEX_LEN/2]={0};
- int main(void)
- {
- size_t i = 0;
- size_t j = 0;
- // parse all charcaters of hex
- while(hex[i] != '