md5 в Erlang
Приклад того, як можна отримати md5 string у erlang
метод1:
md5_hex(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(X) end, L).
int_to_hex(N) when N < 256 ->
[hex(N div 16), hex(N rem 16)].
hex(N) when N < 10 ->
$0+N;
hex(N) when N >= 10, N < 16 ->
$a + (N-10).
приклад:
md5:md5_hex("hello").
"5d41402abc4b2a76b9719d911017c592"
метод2:
md5_hexdigest(String) ->
string:to_lower(
lists:flatten(
lists:map(
fun(V) ->
case httpd_util:integer_to_hexlist(V) of
[A, B] -> [A, B];
[B] -> [$0, B]
end
end,
binary_to_list(erlang:md5(String))
))).
приклад:
md5:md5_hexdigest("hello").
"5d41402abc4b2a76b9719d911017c592"
Читайте також:
- Tutorial: Developing in Erlang with Webmachine, ErlyDTL, and Riak
- Erlang: cpu usage
- Основи Erlang
- Erlang Meter
- Agner: a repository of libraries and applications
- Random shuffle in erlang
- kerl - easy building and installing of Erlang/OTP instances
- URL encode in Erlang
- Python and lists:flatten. Such as in Erlang