MCPcopy Create free account
hub / github.com/LUX-Core/lux / DecodeBase58

Function DecodeBase58

src/base58.cpp:25–69  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23static const char* pszBase58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
24
25bool DecodeBase58(const char* psz, std::vector<unsigned char>& vch)
26{
27 // Skip leading spaces.
28 while (*psz && isspace(*psz))
29 psz++;
30 // Skip and count leading '1's.
31 int zeroes = 0;
32 while (*psz == '1') {
33 zeroes++;
34 psz++;
35 }
36 // Allocate enough space in big-endian base256 representation.
37 std::vector<unsigned char> b256(strlen(psz) * 733 / 1000 + 1); // log(58) / log(256), rounded up.
38 // Process the characters.
39 while (*psz && !isspace(*psz)) {
40 // Decode base58 character
41 const char* ch = strchr(pszBase58, *psz);
42 if (ch == NULL)
43 return false;
44 // Apply "b256 = b256 * 58 + ch".
45 int carry = ch - pszBase58;
46 for (std::vector<unsigned char>::reverse_iterator it = b256.rbegin(); it != b256.rend(); it++) {
47 carry += 58 * (*it);
48 *it = carry % 256;
49 carry /= 256;
50 }
51 assert(carry == 0);
52 psz++;
53 }
54 // Skip trailing spaces.
55 while (isspace(*psz))
56 psz++;
57 if (*psz != 0)
58 return false;
59 // Skip leading zeroes in b256.
60 std::vector<unsigned char>::iterator it = b256.begin();
61 while (it != b256.end() && *it == 0)
62 it++;
63 // Copy result into output vector.
64 vch.reserve(zeroes + (b256.end() - it));
65 vch.assign(zeroes, 0x00);
66 while (it != b256.end())
67 vch.push_back(*(it++));
68 return true;
69}
70
71std::string DecodeBase58(const char* psz)
72{

Callers 3

BIP38_DecryptFunction · 0.85
DecodeBase58CheckFunction · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85

Calls 9

rbeginMethod · 0.80
rendMethod · 0.80
strMethod · 0.80
beginMethod · 0.45
endMethod · 0.45
reserveMethod · 0.45
assignMethod · 0.45
push_backMethod · 0.45
sizeMethod · 0.45

Tested by 1

BOOST_AUTO_TEST_CASEFunction · 0.68