Created
February 2, 2018 03:48
-
-
Save asonge/1e86de5f8c4a63dde4d379a209bca324 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule InvertImage do | |
@magic_reduction_number 20000 | |
@mask :binary.copy(<<255>>, @magic_reduction_number) | |
def invert(binary), do: do_exor(binary, []) | |
defp do_exor("", acc), do: acc | |
defp do_exor(data, acc) when byte_size(data) < @magic_reduction_number, | |
do: [acc | :crypto.exor(data, :binary.copy(<<255>>, byte_size(data)))] | |
defp do_exor(<<data::binary-size(20000), rest::binary>>, acc), | |
do: do_exor(rest, [acc | :crypto.exor(data, @mask)]) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment