How do I base58 encode a string?

farmdve picture farmdve · Jan 23, 2012 · Viewed 16.4k times · Source
char (* text)[1][45+1];
text = calloc(5000,(130+1));
strcpy(0[*text],"sometext)");

Now I want to encode "sometext" to base58, however, I do not know how, and oddly enough, there isn't one example of BASE58 in C.

The base58 encoding I'm interested in uses these symbols:

123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ

It's been optimized to lessen the risk of mis-reading, so 0 and 'O' are both gone, for instance.

P.S Don't mind the weird allocation and declaration of the variables, I was experimenting.

Answer

unwind picture unwind · Jan 23, 2012

You're not supposed to encode strings, you're supposed to encode integers.

If starting with a string, you must first decide how to interpret it as an integer (might be base128, or something), then re-encode in base58.