找到一个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 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
初次前来,多多关照!
[***.217.46.12]2024年04月11日 13时31分53秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
tf dense layer两种创建方式的对比和numpy实现
2019-04-30
tf initializer
2019-04-30
tf keras SimpleRNN源码解析
2019-04-30
tf keras Dense源码解析
2019-04-30
tf rnn输入输出的维度和权重的维度
2019-04-30
检验是否服从同一分布
2019-04-30
tf callbacks
2019-04-30
keras、tf、numpy实现logloss对比
2019-04-30
MyBatisPlus简单入门(SpringBoot)
2019-04-30
攻防世界web进阶PHP2详解
2019-04-30
攻防世界web进阶区web2详解
2019-04-30
xss-labs详解(上)1-10
2019-04-30
xss-labs详解(下)11-20
2019-04-30
攻防世界web进阶区ics-05详解
2019-04-30
攻防世界web进阶区FlatScience详解
2019-04-30
攻防世界web进阶区ics-04详解
2019-04-30
攻防世界web进阶区bug详解
2019-04-30
攻防世界web进阶区ics-07详解
2019-04-30
攻防世界web进阶区unfinish详解
2019-04-30
攻防世界web进阶区i-got-id-200超详解
2019-04-30