Young87

SmartCat's Blog

So happy to code my life!

游戏开发交流QQ群号60398951

当前位置:首页 >跨站数据测试

信息摘要函数(Hash函数)的设计与性质验证

1.信息摘要函数(Hash函数)的设计与性质验证实验

2.实验目的:信息摘要函数(Hash函数)的设计与性质验证。

2.1实验设备:PC机 一台/人

2.2实验原理:

2.2.1.信息摘要函数具有固定的输出数位。

2.2.1信息摘要函数满足不可求逆,不可伪造和在可行时间之内找不到碰撞等特性。

3.实验内容及注意事项:

信息摘要函数的设计与Hash值的性质验证

实验步骤:

3.1设计符合原理要求的信息摘要函数H(m)。

3.2对于如下明文信息m:

There was a grocery shop in a town. Plenty of mice lived in that grocery shop. Food was in plenty for them. They ate everything and spoiled all the bags. They also wasted the bread, biscuits and fruits of the shop. The grocer got really worried. So, he thought "I should buy a cat and let it stay at the grocery. Only then I can save my things." He bought a nice, big fat cat and let him stay there. The cat had a nice time hunting the mice and killing them. The mice could not move freely now. They were afraid that anytime the cat would eat them up. The mice wanted to do something. They held a meeting and all of them tweeted "We must get rid of the cat. Can someone give a suggestion"?  All the mice sat and brooded. A smart looking mouse stood up and said, "The cat moves softly. That is the problem. If we can tie a bell around her neck, then things will be fine. We can know the movements of the cat". “Yes, that is answer," stated all the mice. An old mouse slowly stood up and asked, "Who would tie the bell?" After some moments there was no one there to answer this question. 

调用H(m)算法,产生Hash值。

3.3随机改变m的任意一位字符,产生新的Hash值,

如此实验10次,记新的Hash值为 H1,H2,…H10

3.4设计函数计算H0和Hi 的相似度 i=1,2,…10

3.5分析结果,得出结论

4.实验过程

4.1设计 哈希函数Hash(m)的思路

MD5摘要算法是Hash摘要算法中的一种摘要算法,具有不可求逆性,不可伪造性。MD5 算法自诞生之日起,就有很多人试图证明和发现它的不安全之处,即存在碰撞(在对两个不同的内容使用 MD5算法运算的时候,有可能得到一对相同的结果值)。2009年,中国科学院的谢涛和冯登国仅用了 的碰撞算法复杂度,破解了MD5的碰撞抵抗,该攻击在普通计算机上运行只需要数秒钟 。因此MD5算法不具备实验中要求的“在可行时间之内找不到碰撞”这个特性。
​ 根据MD5的存在的缺点,为了加强MD5加密算法的安全性(本身是不可逆的),从而加入了新的算法部分即加盐值,加盐值是随机生成的一组字符串,可以包括随机的大小写字母、数字、字符,位数可以根据要求而不一样,使用不同的加盐值产生的最终密文是不一样的。由于使用加盐值以后的密码相当的安全,即便是你获得了其中的salt和最终密文,破解也是一个耗费相当多时间的过程,可以说是破解单纯MD5的好几倍。并且同一个明文在经过加盐(这个盐是随机的,不同的)后进行MD5算法产生的密文也是不同的。这就使得MD5算法的抗碰撞性得到大幅度增强,因此可以满足本次实验要求。

4.2MD5+盐的实现步骤

1).首先获取需要进行md5普摘要算法的明文text。
2).随机生成加盐值(可以由字母,数字,字符组成,位数可以自己决定,这里使用16位的字符串)salt字符串.
3)将生成的salt字符串追加到明文text中,得到组合的字符串 mergeText = text +salt
4)使用md5普通摘要算法获取mergeText 的hash值得到一个32位的字符串decodeText。
5).将盐salt字符串的每个字符逐个插入到字符串decodeText是 i *3+1(i = 0,1,2,…16)的位置上,得到一个新的48位的字符串 decode。
6)最终的decode字符串就是所要的密文,位长为48个字符。

该代码已经用c++实现,具体请看:

除特别声明,本站所有文章均为原创,如需转载请以超级链接形式注明出处:SmartCat's Blog

上一篇: 用Java开发贪食蛇小游戏

下一篇: C++实现MD5摘要算法加盐salt值

精华推荐