Skip to content

Instantly share code, notes, and snippets.

@jou

jou/base58.rb

Created Apr 25, 2009
Embed
What would you like to do?
# 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
@kamarules74

This comment has been minimized.

Copy link

@kamarules74 kamarules74 commented Apr 5, 2021

  • ### @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