Skip to content

Instantly share code, notes, and snippets.

@KristerV
Created December 22, 2016 20:09
Show Gist options
  • Save KristerV/67c6cecb293c733a51df6244a6eccb19 to your computer and use it in GitHub Desktop.
Save KristerV/67c6cecb293c733a51df6244a6eccb19 to your computer and use it in GitHub Desktop.
defmodule Arvuti do
def hashit(str, ind, result) do
hash = :crypto.hash(:md5 , str <> to_string(ind)) |> Base.encode16()
cond do
String.length(result) >= 8 ->
result
String.slice(hash, 0..4) == "00000" ->
result = result <> String.slice(hash, 5..5)
IO.puts result
hashit(str, ind+1, result)
true ->
hashit(str, ind+1, result)
end
end
end
IO.puts Arvuti.hashit("abc", 0, "")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment