defmodule Alice.Hasher do @moduledoc """ Alice's implementation of the integer hashing challenge. Uses built-in crypto functions for SHA-256. """ @doc """ Computes SHA-256 hash of a string. """ def sha256(input) do input |> :crypto.hash(:sha256) |> Base.encode16(case: :lower) end @doc """ Sums a list of integers. """ def sum_list(list) do Enum.reduce(list, 0, &(&1 + &2)) end @doc """ Computes factorial recursively. """ def factorial(0), do: 1 def factorial(n), do: n * factorial(n - 1) @doc """ Main entry point that routes to the appropriate function. """ def solve(:sha256, input), do: sha256(input) def solve(:sum_list, input), do: sum_list(input) def solve(:factorial, input), do: factorial(input) def solve(_challenge, _input), do: nil end