<commit_before>defmodule Challenge2 do
  use Bitwise

  @doc """
  Performs bit-wise XOR (exclusive or) on the given binaries `left` and `right`.

  The two arguments must be the same byte size.
  """
  def fixed_xor(left, right) do
    left = decode_hex(left)
    right = decode_hex(right)

    # :crypto.exor(left, right)
    do_fixed_xor(left, right, "")
    |> encode_hex
  end

  defp do_fixed_xor("", "", output) do
    output
  end

  defp do_fixed_xor(<<l_head, l_tail::binary>>, <<r_head, r_tail::binary>>, output) do
    next_byte = <<bxor(l_head, r_head)>>
    do_fixed_xor(l_tail, r_tail, output <> next_byte)
  end

  defp decode_hex(string) do
    Base.decode16!(string, case: :mixed)
  end

  defp encode_hex(string) do
    Base.encode16(string, case: :lower)
  end
end<commit_msg>Simplify Elixir Set1/Challenge2<commit_after>defmodule Challenge2 do
  use Bitwise

  def fixed_xor(left, right) do
    left = Base.decode16!(left, case: :mixed)
    right = Base.decode16!(right, case: :mixed)

    # :crypto.exor(left, right)
    do_fixed_xor(left, right, "")
    |> Base.encode16(case: :lower)
  end

  defp do_fixed_xor("", "", result) do
    result
  end

  defp do_fixed_xor(<<left_byte, left::binary>>, <<right_byte, right::binary>>, result) do
    transformed_byte = <<bxor(left_byte, right_byte)>>
    do_fixed_xor(left, right, result <> transformed_byte)
  end
end
{'fraction_non_alphanumeric': 0.13068592057761733, 'fraction_numerical': 0.010108303249097473, 'mean_word_length': 3.95, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5818078', 'n_tokens_mistral': 539, 'n_tokens_neox': 499, 'n_words': 124}