Last active
July 30, 2020 23:59
-
-
Save havenwood/3b5a973626f6f0081beb78d6866215ab to your computer and use it in GitHub Desktop.
Example Base58 Implementation (showing haxx0r> on #ruby irc)
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
module Base58 | |
CHARACTERS = [*?1..?9, *?a..?k, *?m..?z, *?A..?H, *?J..?N, *?P..?Z].freeze | |
module_function | |
def encode(n) | |
chars = [] | |
while n >= 58 | |
chars.unshift CHARACTERS[n % 58] | |
n -= n % 58 | |
n /= 58 | |
end | |
chars.unshift CHARACTERS[n] | |
chars.join | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
BASE58_CHARACTERS = '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ'
might also do the job? No need for it to be an array?