Skip to content

Instantly share code, notes, and snippets.

@dch
Created May 18, 2014 23:33
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dch/bb33330a6d68b8149103 to your computer and use it in GitHub Desktop.
Save dch/bb33330a6d68b8149103 to your computer and use it in GitHub Desktop.
erlang quick conversion of binary sha hash to printable hex/ascii
(akai@akai)27> Hex=fun(<<Hash:20/big-unsigned-integer-unit:8>>) ->
lists:flatten(io_lib:format("~40.16.0b", [Hash])) end.
#Fun<erl_eval.6.106461118>
(akai@akai)28> Hex(<<200,152,0,191,200,46,208,30,214,227,191,213,64,140,81,39,68,145,247,212>>).
"c89800bfc82ed01ed6e3bfd5408c51274491f7d4"
(akai@akai)29>
@toraritte
Copy link

Thank you so much! Saving these here, in case someone else wants to decipher it quickly:

1> Secret = crypto:hash(sha512, "password").
<<177,9,243,187,188,36,78,184,36,65,145,126,208,109,97,
  139,144,8,221,9,179,190,253,27,94,7,57,76,112,...>>
2> <<SHA512:512/big-unsigned-integer>> = Secret. 
<<177,9,243,187,188,36,78,184,36,65,145,126,208,109,97,
  139,144,8,221,9,179,190,253,27,94,7,57,76,112,...>>
3> io_lib:format("~128.16.0b", [SHA512]).
"b109f3bbbc244eb82441917ed06d618b9008dd09b3befd1b5e07394c706a8bb980b1d7785e5976ec049b46df5f1326af5a2ea6d103fd07c95385ffab0cacbc86"

(from this SO answer)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment