Advertisement
_takumi

hw4r4

Apr 13th, 2022
1,117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. #define BUF_SIZE 4095
  5.  
  6. int hash(char * s) {
  7.     int arr[256];
  8.     int a, b, i = 0, j = 0;
  9.     do {
  10.         a = i;
  11.         b = 0;
  12.         do {
  13.             if ((a & 1) != 0) {
  14.                 a >>= 1;
  15.                 a &= 0x7FFFFFFF;
  16.                 a ^= -306674912;
  17.             } else {
  18.                 a >>= 1;
  19.                 a &= 0x7FFFFFFF;
  20.             }
  21.             b++;
  22.         } while (b != 8);
  23.     arr[i] = a;
  24.     i++;
  25.     } while (i != 256);
  26.     a = -1;
  27.     // --
  28.     i |= s[j];
  29.     while ((i & 0x000000FF) != 0) {
  30.         i ^= a;
  31.         j++;
  32.         i &= 0x000000FF;
  33.         a >>= 8;
  34.         a &= 0x00FFFFFF;
  35.         a ^= arr[i];
  36.         i = s[j];
  37.     }
  38.     // --
  39.     a = ~a;
  40.     return a;
  41. }
  42.  
  43. int main(void) {
  44.     char s[BUF_SIZE];
  45.     fgets(s, sizeof(char) * BUF_SIZE, stdin);
  46.     printf("%x\n", hash(s));
  47.     return 0;
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement