Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include "gmp.h"
- void hashfunc(mpz_t hash, const char *input, const int len) {
- int n,i;
- static int first=1;
- unsigned long c;
- static mpz_t POW14, POW26_1, h14;
- if (first) {
- mpz_init_set_str(POW14, "11112006825558016", 10);
- mpz_init_set_str(POW26_1, "6156119580207157310796674288400203777", 10);
- mpz_init(h14);
- first=0;
- }
- mpz_set_ui(hash, 1);
- for (n=0; n<3; n++) {
- for (i=0; i<len; i++) {
- c = input[i];
- mpz_add_ui(hash, hash, c);
- mpz_mul(h14,hash,POW14);
- mpz_xor(hash,hash,h14);
- mpz_mod(hash,hash,POW26_1);
- }
- }
- }
- int main() {
- mpz_t hash;
- char *tests[] = { "", "Test", "test" };
- int i;
- mpz_init(hash);
- for (i=0; i<sizeof(tests)/sizeof(char*); i++) {
- hashfunc(hash, tests[i], strlen(tests[i]));
- gmp_printf("'%s' => %Zd\n", tests[i], hash);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement