🏋️♂️
This file contains hidden or 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
entropy_bytes | |
|> bit_size() | |
|> div(32) |
This file contains hidden or 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
binary | |
|> :binary.bin_to_list() | |
|> Enum.map(fn byte -> | |
byte | |
|> Integer.to_string(2) | |
|> String.pad_leading(8, "0") | |
end) | |
|> Enum.join() |
This file contains hidden or 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
256 | |
|> div(8) | |
|> :crypto.strong_rand_bytes() |
This file contains hidden or 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
entropy_length | |
|> div(32) | |
|> Kernel.+(entropy_length) | |
|> div(11) |
This file contains hidden or 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
defp duplicate_zeros(count) do | |
"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz" | |
|> String.first() | |
|> String.duplicate(count) | |
en |
This file contains hidden or 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
defp leading_zeros(input) do | |
input | |
|> :binary.bin_to_list() | |
|> Enum.find_index(&(&1 != 0)) | |
end |
This file contains hidden or 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
defp prepend_zeros(acc, input) do | |
input | |
|> encode_zeros() | |
|> apend(acc) | |
end | |
defp encode_zeros(input) do | |
input | |
|> leading_zeros() | |
|> duplicate_zeros() |
This file contains hidden or 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
def call(input, acc) do | |
input | |
|> div(58) | |
|> call(extended_hash(input, acc)) | |
end | |
defp extended_hash(input, acc) do | |
"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz" | |
|> String.at(rem(input, 58)) | |
|> apend(acc) |
This file contains hidden or 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
def call(input, acc \\ "") | |
def call(0, acc), do: acc | |
def call(input, acc) | |
when is_binary(input) do | |
input | |
|> :binary.decode_unsigned() | |
|> call(acc) | |
|> prepend_zeros(input) | |
end |
This file contains hidden or 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
versioned_hash <> checksum |