MCPcopy Create free account
hub / github.com/bitcoinxt/bitcoinxt / EncodeBase64

Function EncodeBase64

src/utilstrencodings.cpp:92–136  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90}
91
92string EncodeBase64(const unsigned char* pch, size_t len)
93{
94 static const char *pbase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
95
96 string strRet="";
97 strRet.reserve((len+2)/3*4);
98
99 int mode=0, left=0;
100 const unsigned char *pchEnd = pch+len;
101
102 while (pch<pchEnd)
103 {
104 int enc = *(pch++);
105 switch (mode)
106 {
107 case 0: // we have no bits
108 strRet += pbase64[enc >> 2];
109 left = (enc & 3) << 4;
110 mode = 1;
111 break;
112
113 case 1: // we have two bits
114 strRet += pbase64[left | (enc >> 4)];
115 left = (enc & 15) << 2;
116 mode = 2;
117 break;
118
119 case 2: // we have four bits
120 strRet += pbase64[left | (enc >> 6)];
121 strRet += pbase64[enc & 63];
122 mode = 0;
123 break;
124 }
125 }
126
127 if (mode)
128 {
129 strRet += pbase64[left];
130 strRet += '=';
131 if (mode == 1)
132 strRet += '=';
133 }
134
135 return strRet;
136}
137
138string EncodeBase64(const string& str)
139{

Callers 4

CallRPCFunction · 0.85
signmessageFunction · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85

Calls 2

reserveMethod · 0.80
sizeMethod · 0.45

Tested by 1

BOOST_AUTO_TEST_CASEFunction · 0.68