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

Function EncodeBase58

src/base58.cpp:86–119  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

84}
85
86std::string EncodeBase58(const unsigned char* pbegin, const unsigned char* pend)
87{
88 // Skip & count leading zeroes.
89 int zeroes = 0;
90 while (pbegin != pend && *pbegin == 0) {
91 pbegin++;
92 zeroes++;
93 }
94 // Allocate enough space in big-endian base58 representation.
95 std::vector<unsigned char> b58((pend - pbegin) * 138 / 100 + 1); // log(256) / log(58), rounded up.
96 // Process the bytes.
97 while (pbegin != pend) {
98 int carry = *pbegin;
99 // Apply "b58 = b58 * 256 + ch".
100 for (std::vector<unsigned char>::reverse_iterator it = b58.rbegin(); it != b58.rend(); it++) {
101 carry += 256 * (*it);
102 *it = carry % 58;
103 carry /= 58;
104 }
105 assert(carry == 0);
106 pbegin++;
107 }
108 // Skip leading zeroes in base58 result.
109 std::vector<unsigned char>::iterator it = b58.begin();
110 while (it != b58.end() && *it == 0)
111 it++;
112 // Translate the result into a string.
113 std::string str;
114 str.reserve(zeroes + (b58.end() - it));
115 str.assign(zeroes, '1');
116 while (it != b58.end())
117 str += pszBase58[*(it++)];
118 return str;
119}
120
121std::string EncodeBase58(const std::vector<unsigned char>& vch)
122{

Callers 3

BIP38_EncryptFunction · 0.85
EncodeBase58CheckFunction · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85

Calls 7

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

Tested by 1

BOOST_AUTO_TEST_CASEFunction · 0.68