MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / EncodeBase58

Function EncodeBase58

src/base58.cpp:83–121  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 4

EncodeBase58CheckFunction · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85
DummyAddressFunction · 0.85
Base58EncodeFunction · 0.85

Calls 8

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

Tested by 1

BOOST_AUTO_TEST_CASEFunction · 0.68