Created
May 24, 2016 16:05
-
-
Save liangfu/5b7bc147c6acd22a5ce6fa9cc11006f1 to your computer and use it in GitHub Desktop.
simple hash string code in c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
char num2char(size_t num){ | |
char res = 0; int val = num%62; | |
if (val<10){ res = val+48; | |
}else if (val>=10&&val<36){ res = val+65-10; | |
}else if (val>=36&&val<62){ res = val+97-36; | |
}return res; | |
} | |
void swap(char & a, char & b){char t=b;b=a;a=t;} | |
void hash(char * src, char * dst, int sz){ | |
memcpy(dst,src,32); | |
static int swap_table[32]={/* shuffled 0 .. 31 */}; | |
int i; const int maxiter=32; | |
for (int iter=0;iter<maxiter;iter++){ | |
for (i=0;i<32;i++){swap(dst[31-swap_table[i]],dst[swap_table[i]]);} | |
for (i=0;i<32;i++){dst[i]+=swap_table[i]-16;} | |
for (i=0;i<32;i++){ | |
dst[i]=num2char(int(dst[i])+ | |
int(dst[swap_table[i]])+ | |
237); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment