关注LAMP|PHP源代码分析|web架构|PHP扩展|Erlang|服务端架构

Erlang中计算16位的MD5字符串

2010-01-18

原创文章,转载请注明: 转载自庆亮的博客-webgame架构

本文链接地址: Erlang中计算16位的MD5字符串

 

erlangbif中自带了md5计算函数,但是结果却是二进制的,即使转成list,也是10进制表示,google了一下得到一段代码用于获得字符串形式的md5结果(16位):

md5(S) ->        

Md5_bin =  erlang:md5(S), 

Md5_list = binary_to_list(Md5_bin), 

lists:flatten(list_to_hex(Md5_list)). 

 

list_to_hex(L) -> 

lists:map(fun(X) -> int_to_hex(XendL). 

 

int_to_hex(Nwhen N < 256 -> 

[hex(N div 16), hex(N rem 16)]. 

hex(Nwhen N < 10 -> 

       $0+N

hex(Nwhen N >= 10N < 16 ->      

$a + (N-10).

英文链接  http://sacharya.com/md5-in-erlang/

作者:庆亮 | 分类目录:Erlang | 标签:

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>