-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to encode a string to base58? #1
Comments
We can use the following
|
Creating the recursive function to convert an integer to a list of base58 point was at the end simple enough (we might found a better way to do this later on see #2)
Adding now a Readme and some tests |
I'm going to update the Readme to
On the code:
|
@SimonLab this list of additions to the Please liaise with @Danwhy on property-based-testing if you need. |
To be able to use property-based-testing we need to find another library which can produce a base58 string. Once we have something to compare to we should be able to run as much test as we want. We could maybe use a node package, or the other elixir package? Or a bash command line tool? |
@SimonLab if you need a "reference" library for Base58 see: https://github.com/bitcoin/bitcoin/blob/master/src/base58.h That way we can claim to have 100% Compatibility with the Bitcoin Base58.
|
I've added a property test using basefiftyeight library to compare our result. |
@SimonLab this is a good short-term solution. thanks for opening the |
initial version merged, #3 and the documentation has been updated |
Given a string what are the steps to get the base58 encoded value?
Base.encode16
"foo" in utf8 is represented with the codepoint
<<102, 111, 111>>. You can see this representation with
"foo" <> <<0>>` which concatane <<0>> to the string. Then 102 in hex is 66 and 6F is 111Calculate the integer for 66 6F 6F
6 * 16^5 + 6 * 16^4 + 6 * 16^3 + 15 * 16^2 + 6 * 16^1 + 15 * 16^0 = 6713199
(where the hexadecimal F is 15 in decimal)
Encode the decimal value to base58 codepoint
take the rest of the division by 58 and repeat on the rest of the division until we can't divide by 58
6713199 % 58 = 47 and rest 115744 (% here is the modulo operator)
115744 % 58 = 34
1995 % 58 = 23
34 % 58 = 34
We have the list 34 23 34 47
34 is b
23 is Q
47 is p
For that you just need to find the letter at the indice
123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz
012345... ...57
So "foo" in base58 is "bQbp"
I haven't find a function to convert directly a string (binary) to the integer represetation ie "foo" to 6713199. So the first steps is to create this function.
Then we can create the function which calculate the modulo of these number with 58 and find the characters at the indices calculated
The text was updated successfully, but these errors were encountered: