Guest User

Untitled

a guest
Oct 17th, 2017
406
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.74 KB | None | 0 0
  1. unsigned char hex[64] = 9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a0"
  2.  
  3. 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 }
  4.  
  5. for(i=0; i< strlen(tmpInHash); i++ {
  6. printf("%c ", tmpInHash);
  7. }
  8.  
  9. 0x9f 0x86 0xd0 0x81 0x88 0x4c 0x7d 0x65 0x9a ...
  10.  
  11. #include <stdio.h>
  12. #include <string.h>
  13.  
  14. int main(void)
  15. {
  16. unsigned char hex[] = "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08";
  17.  
  18. size_t stringLength = (sizeof(hex)/sizeof(hex[0]))-1;
  19.  
  20. unsigned char tmpInHash[stringLength/2];
  21.  
  22. int j=0;
  23.  
  24. // reset the char to 0. This grants that next or operation works on reset buffer
  25. tmpInHash[0] = 0;
  26.  
  27. // loop that parse the whole string
  28. for (size_t i = 0; i < stringLength; i++)
  29. {
  30. // check if the char is a to f
  31. if ((hex[i] >= 'a') && (hex[i] <= 'f'))
  32. {
  33. tmpInHash[j] |= hex[i] -'a' + 10;
  34. }
  35. // che if is a digit
  36. else if ((hex[i] >= '0') && (hex[i] <= '9'))
  37. {
  38. tmpInHash[j] |= hex[i] -'0';
  39. }
  40. // character not allowed
  41. else
  42. {
  43. fprintf(stderr, "Character not allowed: %c position: %zun", hex[i], i);
  44. return 1;
  45. }
  46.  
  47. // even index chars are hig 4 bits of unsigned char
  48. if ((i%2) == 0)
  49. {
  50. tmpInHash[j]<<=4;
  51. }
  52. else
  53. {
  54. // nex unsigned char
  55. j++;
  56.  
  57. // reset the char to 0. This grants that next or operation works on reset buffer
  58. if (j < stringLength/2)
  59. tmpInHash[j] = 0;
  60. }
  61.  
  62. }
  63.  
  64. for (size_t i = 0; i < stringLength/2; i++)
  65. {
  66. printf("0x%02X ", tmpInHash[i]);
  67. }
  68.  
  69. printf("n");
  70.  
  71.  
  72. return 0;
  73. }
  74.  
  75. 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
  76.  
  77. #include <stdio.h>
  78. #include <string.h>
  79.  
  80. unsigned char hex[] = "9f86d081884g7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08";
  81.  
  82. #define HEX_LEN (sizeof(hex)-1)
  83.  
  84. unsigned char tmpInHash[HEX_LEN/2]={0};
  85.  
  86. int main(void)
  87. {
  88. size_t i = 0;
  89. size_t j = 0;
  90.  
  91. // parse all charcaters of hex
  92. while(hex[i] != '')
  93. {
  94. // check if the char is a to f
  95. if ((hex[i] >= 'a') && (hex[i] <= 'f'))
  96. {
  97. tmpInHash[j] |= hex[i] -'a' + 10;
  98. }
  99. // che if is a digit
  100. else if ((hex[i] >= '0') && (hex[i] <= '9'))
  101. {
  102. tmpInHash[j] |= hex[i] -'0';
  103. }
  104. // character not allowed
  105. else
  106. {
  107. fprintf(stderr, "Character not allowed: %c position: %zun", hex[i], i);
  108. return 1;
  109. }
  110.  
  111. // even index chars are hig 4 bits of unsigned char
  112. if ((i%2) == 0)
  113. {
  114. tmpInHash[j]<<=4;
  115. }
  116. else
  117. {
  118. // nex unsigned char
  119. j++;
  120. }
  121.  
  122. // next hex char
  123. i++;
  124. }
  125.  
  126. // print loop
  127. for (i = 0; i < (HEX_LEN/2); i++)
  128. {
  129. printf("0x%02X ", tmpInHash[i]);
  130. }
  131.  
  132. printf("n");
  133.  
  134. return 0;
  135. }
  136.  
  137. unsigned char hex[64] = "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a0";
  138. unsigned char *ptrHex =hex;
  139. unsigned char tmpInHash[32];
  140. int i ,tmp ;
  141. for(i=0 ; i < 32 ; i++)
  142. {
  143. if((*ptrHex)<=9 && (*ptrHex) >=0)
  144. tmp=(*ptrHex)-'0';
  145. else tmp=(*ptrHex)-'a'+10;
  146. tmpInHash[i]=(tmp<<4);
  147. ptrHex++;
  148.  
  149. if((*ptrHex)<=9 && (*ptrHex) >=0)
  150. tmp=(*ptrHex)-'0';
  151. else tmp=(*ptrHex)-'a'+10;
  152.  
  153. tmpInHash[i]|=tmp ;
  154. ptrHex++;
  155. }
Add Comment
Please, Sign In to add comment