Skip to content

Instantly share code, notes, and snippets.

@radcliff
Forked from jou/base58.rb
Created March 5, 2016 07:32
Show Gist options
  • Save radcliff/dde392d54c0d72e46b9b to your computer and use it in GitHub Desktop.
Save radcliff/dde392d54c0d72e46b9b to your computer and use it in GitHub Desktop.
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
# Version 2, December 2004
#
# Copyright (C) 2004 Sam Hocevar
# 14 rue de Plaisance, 75014 Paris, France
# Everyone is permitted to copy and distribute verbatim or modified
# copies of this license document, and changing it is allowed as long
# as the name is changed.
#
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
#
# 0. You just DO WHAT THE FUCK YOU WANT TO.
module Base58
def self.encode(n)
alphabet = %w(
1 2 3 4 5 6 7 8 9
a b c d e f g h i
j k m n o p q r s
t u v w x y z A B
C D E F G H J K L
M N P Q R S T U V
W X Y Z
)
return alphabet[0] if n == 0
result = ''
base = alphabet.length
while n > 0
remainder = n % base
n = n / base
result = alphabet[remainder] + result
end
result
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment