   defp from_mixed(char),
     do: char
 
-  defp maybe_pad(<<>>, _, _, _),
-    do: <<>>
   defp maybe_pad(subject, false, _, _),
     do: subject
-  defp maybe_pad(subject, _, group_size, _) when rem(byte_size(subject), group_size) == 0,
-    do: subject
-  defp maybe_pad(subject, _, group_size, pad),
-    do: String.ljust(subject, byte_size(subject) + (group_size - rem(byte_size(subject), group_size)), pad)
+  defp maybe_pad(subject, _, group_size, pad) do
+    case rem(byte_size(subject), group_size) do
+      0 -> subject
+      x -> subject <> String.duplicate(pad, group_size - x)
+    end
+  end
 
   @doc """
   Encodes a binary string into a base 16 encoded string.

        <<>> ->
          <<>>
      end
      main <> maybe_pad(tail, pad_flag, 8, ?=)
    end
  end

  defp do_decode32(_, <<>>, _), do: <<>>
  defp do_decode32(case, string, false),
    do: do_decode32(case, maybe_pad(string, true, 8, ?=), true)

  for {case, fun} <- [upper: :from_upper, lower: :from_lower, mixed: :from_mixed] do
    defp do_decode32(unquote(case), string, _pad_flag) when rem(byte_size(string), 8) == 0 do

        <<>> ->
          <<>>
      end
      main <> maybe_pad(tail, pad_flag, 8, "=")
    end
  end

  defp do_hex_decode32(_, <<>>, _), do: <<>>
  defp do_hex_decode32(case, string, false),
    do: do_hex_decode32(case, maybe_pad(string, true, 8, "="), true)

  for {case, fun} <- [upper: :from_upper, lower: :from_lower, mixed: :from_mixed] do
    defp do_hex_decode32(unquote(case), string, _pad_flag) when rem(byte_size(string), 8) == 0 do
