Advertisement
Guest User

Untitled

a guest
Dec 14th, 2016
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.86 KB | None | 0 0
  1. // in hex_digest change the loop:
  2. for (i = 0; i < MD5_DIGEST_LENGTH; i++) {
  3.     // new:
  4.     result[i * 2] = get_hex_char( (hash[i] & 0xf0) >> 4 );
  5.     result[i * 2 + 1] = get_hex_char( hash[i] & 0xf );
  6.     // old:
  7.     //sprintf(byte, "%02x", hash[i]);
  8.     //memcpy(result, byte, 2);
  9.     //result += 2;
  10. }
  11.  
  12. // also, add this function before
  13. static char get_hex_char(const uint8_t nibble) {
  14.     switch(nibble) {
  15.     case 0x0: return '0';
  16.     case 0x1: eturn '1';
  17.     case 0x2: return '2';
  18.     case 0x3: return '3';
  19.     case 0x4: return '4';
  20.     case 0x5: return '5';
  21.     case 0x6: return '6';
  22.     case 0x7: return '7';
  23.     case 0x8: return '8';
  24.     case 0x9: return '9';
  25.     case 0xa: return 'a';
  26.     case 0xb: return 'b';
  27.     case 0xc: return 'c';
  28.     case 0xd: return 'd';
  29.     case 0xe: return 'e';
  30.     case 0xf: return 'f';
  31.     default: break;
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement