Questo topic e' stato chiuso dal moderatore.
15/01/10 16:46
jock
ragazzi sapete dirmi in questo codice quale la stringa che genera il codice hash se non sbaglio e in c se non e cosi cambiate sezione...
#include <stdio.h> #include <string.h> #include <stdlib.h> #if defined WIN32 typedef unsigned int u_int32_t; #else #include <sys/types.h> #endif u_int32_t hash (u_int32_t key) { key = ~key + (key << 15); key = key ^ (key >> 12); key = key + (key << 2); key = key ^ (key >> 4); key = key * 2057; key = key ^ (key >> 16); return key; } char* str_to_hash (char *str) { u_int32_t *v; int i; int len=strlen(str); char *h; char buff[9]; v = (u_int32_t*) malloc(len*sizeof(u_int32_t)); for (i=0; i<len; i++) v[i] = hash((u_int32_t) str[i]); h = (char*) malloc(8*len*sizeof(char)); memset (h,0x0,sizeof(str)); for (i=0; i<len; i++) { snprintf (buff,sizeof(buff),"%x",v[i]); strcat (h,buff); } return h; } main (int argc, char **argv) { int len; char *str; if (!argv[1]) exit(1); printf ("%s\n",str_to_hash(argv[1])); }
Ultima modifica effettuata da jock 15/01/10 16:47
aaa