Skip to content

Instantly share code, notes, and snippets.

@havenwood
Last active July 30, 2020 23:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save havenwood/3b5a973626f6f0081beb78d6866215ab to your computer and use it in GitHub Desktop.
Save havenwood/3b5a973626f6f0081beb78d6866215ab to your computer and use it in GitHub Desktop.
Example Base58 Implementation (showing haxx0r> on #ruby irc)
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
@RandomEtc
Copy link

BASE58_CHARACTERS = '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ' might also do the job? No need for it to be an array?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment