Base Converter ============== Arbitrary precision base conversion by Daniel Gehriger Permission for use was given `here `_. This has been heavily modified since copying, has been hardcoded for a specific case, then translated to C. .. c:var:: const static char *base_58 This buffer contains all of the characters within the base_58 "alphabet" .. c:var:: const static char *ascii This buffer contains all of the characters within the extended ascii "alphabet" .. c:function:: static size_t find_base_58(const char search) This is the equivalent of base_58.indexOf(search) :param search: The character you would like to search for :returns: The index of this character in base_58, or -1 .. c:function:: static unsigned long long from_base_58(const char *str, const size_t len) This converts a short base_58 buffer to its ascii equivalent :param str: The buffer you wish to convert :param len: The length of the buffer to convert :returns: The equivalent integral value .. c:function:: static unsigned int base2dec(const char *value, const size_t len) Converts a small ascii buffer to its equivalent integral value :param value: The buffer you wish to convert :param len: The length of the buffer to convert :returns: The equivalent integral value .. c:function:: static void dec2base(unsigned int value, char *result, size_t *len) Converts an integral value to its equivalent binary buffer, then places this in result and updates len :param value: The value you wish to convert (as an unsigned int) :param result: The buffer result :param len: The length of the buffer result .. note:: This uses :c:func:`memmove` to transfer data, so it's helpful if you start with a larger-than-necessary buffer .. c:function:: static char *to_base_58(unsigned long long i, size_t *len) Converts an integral value to base_58, then updates len :param i: The value you want to convert :param len: The length of the generated buffer :returns: A buffer containing the base_58 equivalent of ``i`` .. note:: The return value needs to have :c:func:`free` called on it at some point .. c:function:: static unsigned int divide_58(char *x, size_t *length) Divides an ascii buffer by 58, and returns the remainder :param x: The binary buffer you wish to divide :param length: The length of the buffer :returns: An unsigned int which contains the remainder of this division .. c:function:: static char *ascii_to_base_58_(const char *input, size_t length, size_t *res_len) Converts an arbitrary ascii buffer to its base_58 equivalent. The length of this buffer is placed in res_len. :param input: An input buffer :param length: The length of said buffer :param res_len: A pointer to the return buffer's length :returns: A buffer containing the base_58 equivalent of the provided buffer. .. c:function:: static char *ascii_to_base_58(const char *input, size_t length, size_t *res_len, size_t minDigits) Converts an arbitrary ascii buffer into its base_58 equivalent. This is largely used for converting hex digests, or other such things which cannot conveniently be converted to an integral. :param input: An input buffer :param length: The length of said buffer :param res_len: A pointer to the return buffer's length :param minDigits: The minimum number of base_58 digits you would like to get back :returns: A buffer containing the base_58 equivalent of the provided buffer.