文件名称:暴雪字符串哈希.txt
文件大小:5KB
文件格式:TXT
更新时间:2023-02-09 04:51:09
暴雪字符串哈希 算法 代码
/* 函数名:HashString 功能:计算字符串的哈希值 参数:lpszString:字符串的地址 dwHashType:哈希值类型 dwHashType = 0时计算的哈希值用于确定字符串在哈希表中的位置; dwHashType = 1,dwHashType = 2时计算的哈希值用于验证字符串 返回值:字符串的哈希值 */ unsigned long HashString(char *lpszString, unsigned long dwHashType) { unsigned char *key = (unsigned char *)lpszString; unsigned long seed1 = 0x7FED7FED, seed2 = 0xEEEEEEEE; int ch; while(*key != 0) { ch = toupper(*key++); seed1 = cryptTable[(dwHashType << 8) + ch] ^ (seed1 + seed2); seed2 = ch + seed1 + seed2 + (seed2 << 5) + 3; } return seed1; }