如何将短语和单词转换为MD5哈希? [英] How to transform phrases and words into MD5 hash?

查看:131
本文介绍了如何将短语和单词转换为MD5哈希?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以向我解释如何将我想买一些牛奶这样的短语转换成MD5吗?我读了关于MD5的维基百科文章,但是给出的解释超出了我的理解范围:
$ b


MD5处理可变长度
消息转换为
128位的固定长度输出,输入消息被破坏
分成512位块
(16个32位小端b $ b整数)块

16个32位小端序列对我来说已经很难了。我检查了维基文章中的小端,并且没有明白。



然而,Wiki文章中的一些短语和MD5散列的例子非常好:


MD5(快速棕色狐狸跳过
懒狗)=
9e107d9d372bb6826bd81d3542a419d6



MD5(快速棕色狐狸跳过
懒狗。)=
e4d909c290d0fb1ca068ffaddf22cbd0


请问任何人,请向我解释一下这个MD5算法是如何工作的?

另外,也许你知道一些软件或代码可以将短语转换成他们的MD5。如果是,请告诉我。

解决方案

忘记endians:这只是一种方式来编码信息的方式。



让我们按照wikipedia MD5 文章。你从一个输入消息开始。它可以是任意长的:对于2GB ISO文件,MD5散列是常规创建的,就像十几个字符长的字符串的散列(例如对于密码)一样。



包含在寄存器 a 中, b c d 。这些寄存器被初始化为特殊值( h0-h3 )。



字节块(16个32位小端字),并应用特定的逻辑操作(函数 F G H I )的部分输入和寄存器的当前状态 a b c d 。它为每个16个4字节的块组执行64次。



当所有的块都被处理时, a b c d 是最后一个散列,可以通过调用 md5sum testfile.txt



更新:



如果你只是想计算一个哈希,你自己实现它是没有意义的,因为它已经完成并测试了可能每种重要语言:

Python

  import md5 
md5.new(没有人检查垃圾邮件重复)digest()

SQL(

  SELECT MD5('没有人检查垃圾邮件重复') 

Java

  String s =没有人检查垃圾邮件的重复; 
MessageDigest m = MessageDigest.getInstance(MD5);
m.update(s.getBytes(),0,s.length());
System.out.println(new BigInteger(1,m.digest())。toString(16));

等。


Can anyone, please, explain to me how to transform a phrase like "I want to buy some milk" into MD5? I read Wikipedia article on MD5, but the explanation given there is beyond my comprehension:

"MD5 processes a variable-length message into a fixed-length output of 128 bits. The input message is broken up into chunks of 512-bit blocks (sixteen 32-bit little endian integers)"

"sixteen 32-bit little endian integers" is already hard for me. I checked the Wiki article on little endians and didn't understand a bit.

However, the examples of some phrases and their MD5 hashes in that Wiki article are very nice:

MD5("The quick brown fox jumps over the lazy dog") = 9e107d9d372bb6826bd81d3542a419d6

MD5("The quick brown fox jumps over the lazy dog.") = e4d909c290d0fb1ca068ffaddf22cbd0

Can anyone, please, explain to me how this MD5 algorithm works using some very simple example?

And also, perhaps you know some software or a code that would transform phrases into their MD5. If yes, please, let me know.

解决方案

Forget about the endians: it's just a way name for a way to encode information.

Let's follow the wikipedia MD5 article. You start with an input message. It can be arbitrarily long: MD5 hashes for 2GB ISO files are routinely created, just like hashes for strings a dozen characters long (e.g. for passwords).

The hash will be contained in registers a , b, c and d. These registers are initialized with special values (h0-h3).

The algorithm breaks the input into 16 4-byte chunks ("sixteen 32-bit little-endian words") and applies specific logical operations (functions F, G, H and I) on parts of the input and the current state of registers a , b, c and d. It does this 64 times for each set of 16 4-byte chunks.

When all of the chunks are processed, what remains in a , b, c and d is the final hash, the one you might get by invoking md5sum testfile.txt.

Update:

If you just want to be able to calculate a hash, implementing it yourself makes no sense because it's been done and tested for probably every significant language out there:

Python:

import md5
md5.new("Nobody inspects the spammish repetition").digest()

SQL (MySQL):

SELECT MD5('Nobody inspects the spammish repetition')

Java:

String s="Nobody inspects the spammish repetition";
MessageDigest m=MessageDigest.getInstance("MD5");
m.update(s.getBytes(),0,s.length());
System.out.println(new BigInteger(1,m.digest()).toString(16));

etc.

这篇关于如何将短语和单词转换为MD5哈希?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆