Advertisement
Guest User

Untitled

a guest
Apr 1st, 2015
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. #include <stdio.h>
  2. #define BUF_SIZE 4095
  3.  
  4. char buf[BUF_SIZE + 1];
  5.  
  6. unsigned hash(char* s)
  7. {
  8. unsigned edx = 0, eax;
  9. char* ecx = s;
  10.  
  11. unsigned esi[256];
  12.  
  13. for ( edx = 0; edx < 256; ++edx )
  14. {
  15. eax = edx;
  16.  
  17. for ( unsigned ebx = 0; ebx < 8; ++ebx )
  18. {
  19. if ( eax & 1 )
  20. {
  21. eax >>= 1;
  22. eax ^= -306674912;
  23. }
  24. else { eax >>= 1; }
  25. }
  26.  
  27. esi[edx] = eax;
  28. }
  29.  
  30. eax |= -1;
  31.  
  32. while ( (edx = (edx & 256) | *ecx) & 255 )
  33. {
  34. edx ^= eax;
  35. ++ecx;
  36.  
  37. edx = edx & 255;
  38. eax >>= 8;
  39. eax ^= esi[edx];
  40. }
  41.  
  42. return ~eax;
  43. }
  44.  
  45. int main(void)
  46. {
  47. buf[0] = 0;
  48. fgets(buf, BUF_SIZE, stdin);
  49. buf[BUF_SIZE] = 0;
  50.  
  51. printf("%x\n", hash(buf));
  52. return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement