找到一个hash函数
发布日期:2021-06-30 22:10:30 浏览次数:2 分类:技术文章

本文共 830 字,大约阅读时间需要 2 分钟。

前言

在lua5.3.3代码中看到一个hash函数,摘出来玩玩。

试验

// hw.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include 
#include
#include
#include
#include
unsigned int hashProc(const char* pcSrc, size_t l, unsigned int seed){ unsigned int h = seed ^(unsigned int)l; size_t step = (l >> 5) + 1; for (; l >= step; l -= step) { h ^= ((h << 5) + (h >> 2) + (BYTE)pcSrc[l - 1]); } return h;}int main(int argc, char* argv[]){ srand((UINT)time(NULL)); const char* pcMsg = "string for calc hash"; UINT iHash = hashProc(pcMsg, strlen(pcMsg), rand()); printf("hash value = 0x%X, str = [%s]\r\n", iHash, pcMsg); system("pause"); /** run result hash value = 0xEE996D0, str = [string for calc hash] 请按任意键继续. . . */ return 0;}

转载地址:https://lostspeed.blog.csdn.net/article/details/52598252 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:DotNet程序的判断依据
下一篇:算法还原练习-20160920

发表评论

最新留言

初次前来,多多关照!
[***.217.46.12]2024年04月11日 13时31分53秒