7 void hash (const char *in
, char hash
[16])
10 unsigned char list
[size
];
12 for (i
= 0; i
< size
; i
++)
16 const char suffix
[6] = { 17, 31, 73, 47, 23 };
17 char *str
= malloc(strlen(in
) + 5 + 1);
18 strcpy(stpcpy(str
, in
), suffix
);
19 for (int j
= 0; j
< 64; j
++) {
20 for (char *p
= str
; *p
; p
++) {
22 for (i
= 0; i
< length
/ 2; i
++) {
23 int tmp
= list
[(i
+ pos
) % size
];
24 list
[(i
+ pos
) % size
] = list
[(length
- i
- 1 + pos
) % size
];
25 list
[(length
- i
- 1 + pos
) % size
] = tmp
;
27 pos
+= length
+ skip
++;
31 for (i
= 0; i
< size
; i
++) {
43 void visit (int n
, int x
, int y
)
45 if (x
< 0 || y
< 0 || x
> 127 || y
> 127)
47 if (grid
[x
][y
] == 1) {
56 int main(int argc
, char **argv
)
62 int len
= asprintf(&str
, "%s-127", argv
[1]);
63 char *p
= str
+ len
- 3;
66 for (i
= 0; i
< 128; i
++) {
69 if (getenv ("DEBUG")) {
70 printf ("hash of %s was ", str
);
71 for (j
= 0; j
< sizeof h
; j
++)
72 printf ("%02hhx", h
[j
]);
75 for (j
= 0; j
< sizeof h
; j
++)
76 for (int k
= 0; k
< 8; k
++)
77 if ((1 << (7 - k
)) & h
[j
])
78 grid
[i
][j
* 8 + k
] = !!++count
;
80 printf ("total of %d dirty blocks\n", count
);
82 for (i
= 0; i
< 128; i
++)
83 for (j
= 0; j
< 128; j
++)
84 if (grid
[i
][j
] == 1) {
86 printf ("marking region %d at %d,%d\n", regions
, i
, j
);
87 visit (++regions
, i
, j
);
89 printf ("total of %d regions\n", regions
- 1);