tkislan / base64 Goto Github PK
View Code? Open in Web Editor NEWBase64 encoding and decoding for C++ projects
License: MIT License
Base64 encoding and decoding for C++ projects
License: MIT License
I noticed the library fails with base64 encoded wrapped text (typically column text). Wrapped text can be obtained for example by using this online tool and clicking "Split lines into 76 character wide chunks", I fixed it by improving DecodeLength
function and skipping newlines also in Decode
. I changed the code a bit to adapt to my tastes but it should give the idea of what is needed to fix it:
size_t DecodedLength(const char *str, size_t len)
{
size_t numEq = 0;
size_t size = 0;
for (size_t i = 0; i < len; i++) {
char ch = str[i];
if (ch == '\n' || ch == '\r')
continue;
if (ch == '=')
numEq++;
size++;
}
return ((6 * size) / 8) - numEq;
}
bool Decode(const char *str, size_t len, std::string &out)
{
int i = 0, j = 0;
size_t dec_len = 0;
unsigned char a3[3];
unsigned char a4[4];
out.resize(DecodedLength(str, len));
while (len--) {
char ch = *str;
if (ch == '=') {
break;
}
if (ch == '\n' || ch == '\r') {
str++;
continue;
}
a4[i++] = *(str++);
if (i == 4) {
for (i = 0; i < 4; i++) {
a4[i] = b64_lookup(a4[i]);
}
a4_to_a3(a3, a4);
for (i = 0; i < 3; i++) {
out[dec_len++] = a3[i];
}
i = 0;
}
}
if (i) {
for (j = i; j < 4; j++) {
a4[j] = '\0';
}
for (j = 0; j < 4; j++) {
a4[j] = b64_lookup(a4[j]);
}
a4_to_a3(a3, a4);
for (j = 0; j < i - 1; j++) {
out[dec_len++] = a3[j];
}
}
return (dec_len == out.size());
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.