Skip to content

Instantly share code, notes, and snippets.

@hamiltop
Created January 5, 2016 01:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hamiltop/0c83ada42b5557b9785a to your computer and use it in GitHub Desktop.
Save hamiltop/0c83ada42b5557b9785a to your computer and use it in GitHub Desktop.
[file | _ ] = System.argv
file_stream = File.stream!(file)
context = :crypto.hash_init(:md5)
context = Enum.reduce(file_stream, context, fn (data, cxt) ->
:crypto.hash_update(cxt, data)
end)
int_value = :binary.decode_unsigned :crypto.hash_final(context)
IO.puts String.downcase Integer.to_string(int_value, 16)
@hamiltop
Copy link
Author

hamiltop commented Jan 5, 2016

> elixir md5.exs /etc/hosts
fb0cb12d0bc7744769cf8f555ec690a1
> md5 /etc/hosts
MD5 (/etc/hosts) = fb0cb12d0bc7744769cf8f555ec690a1

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