LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Need Help with Base58 encoding

Solved!
Go to solution

base58 FP.jpg

This is driving me nuts. I attempted to modify a base64 VI. I get the 51 characters I am looking for but they are not correct.  I am using the modified base58 Character set, it doesn't use 0O or L.base58.jpg

0 Kudos
Message 1 of 10
(2,264 Views)

Hi n2,

 

there is so much wrong in your VI…

 

First point: there is no comment describing the algorithm you want to implement! How should we (and you) know, if your implementation fits to your requirements when you don't document the requirements?

 

Next point: silly implementations and using wrong datatypes!

Example:

Your implementation at the top uses way too much code, produces coercion dots, does silly conversions (from should-be U8 array to string and back to U8 array). The implementation below produces the same output in the correct datatype (for valid inputs)…

 

This one is also very silly:

What is the expected remainder when you calculate the remainder of an integer number divided by 1?

 

Why are there any orange wires at all? You should NEVER try to index bits from a boolean array using fractional indexes! (Here my first point comes into play: please describe/document the algorithm you want to implement!)

Why is the output labelled "Base64" when all the rest talks about "Base58"?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Download All
0 Kudos
Message 2 of 10
(2,206 Views)

Thank you much for the tip!  So the base58 in this case is specific to Bitcoin and some other cryptocurrency's. 
In my Front panel shows a valid hey derived from the hex input. If use another program or web API, I get the correct private key output  (5KasYynWv1ZtzvEAmvb51a4FpbA4hUwf78Y6L2kdbLZnNDpHBPZ) This Key will always start with 5 as the hex key is always prefixed with 4 bytes (80) then double hashed with sha-256 and a checksum.  Here is a quick explanation of the base58 I am trying implement. https://en.wikipedia.org/wiki/Base58. The idea was to create an app so that I can covert the hex private key to  what is known as WIF, Wall import format.  This is more of journey to for me to understand the cryptography behind it. Forgive my playing around the fractions. I am just having troubling visualizing the code. I for to mention that the letter uppercase (i) is also excluded in this implementation.  The erroy message is silly but I didn't do that. That was example found I found for base64. Thanks so much for you help!

Tom 

0 Kudos
Message 3 of 10
(2,180 Views)

Hi n2,

 

here's what I found about Base58 encoding.

See how far you get with this algorithm and ask when you run into specific problems…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 4 of 10
(2,174 Views)
Solution
Accepted by topic author n2new

Hi,

 

Base64 algorithm cannot be applied on base58. Here's an example I created based on the algorithm described here.

Message 5 of 10
(2,167 Views)

From https://en.bitcoin.it/wiki/Base58Check_encoding:

 

   code_string = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
   x = convert_bytes_to_big_integer(hash_result)
   
   output_string = ""
   
   while(x > 0) 
       {
           (x, remainder) = divide(x, 58)
           output_string.append(code_string[remainder])
       }
   
   repeat(number_of_leading_zero_bytes_in_hash)
       {
       output_string.append(code_string[0]);
       }
   
   output_string.reverse();

 

0 Kudos
Message 6 of 10
(2,164 Views)
Solution
Accepted by topic author n2new

@TCChun wrote:

Hi,

 

Base64 algorithm cannot be applied on base58. Here's an example I created based on the algorithm described here.


That inner while loop is a for loop with auto indexing. That will be faster.

 

In the first for loop, the build array can be replaced with concatenating indexing. The VI was probably build before that was possible? Benefit of the doubt...

 

Repeating converting the Boolean array to number will be slow... Rotate Left With Carry does exactly that.

 

The last loop is redundant.

 

Anyway, AFAIC your post should be marked as solution.

 

Before:

Spoiler
Util Convert to Base58 (org).png

After:

Spoiler
Util Convert to Base58.png

 

 

Message 7 of 10
(2,155 Views)

Thanks, I have labview 2016 only, could you save for previous version and repost?  Thanks!

Tom

0 Kudos
Message 8 of 10
(2,150 Views)
Solution
Accepted by topic author n2new
Message 9 of 10
(2,144 Views)

Thanks much! As usual, the solution should have been obvious to me!

Message 10 of 10
(2,137 Views)