Jump to content

Base64 decode data: Difference between revisions

→‎{{header|C++14}}: simplifications
(Bash decode)
(→‎{{header|C++14}}: simplifications)
Line 216:
 
=={{header|C++}}==
{{Works with|C++14}}
<lang cpp>#include <algorithm>
#include <iostream>
Line 298 ⟶ 299:
auto i1 = findIndex(b1);
auto i2 = findIndex(b2);
auto acc = i1 << 2; // six bits came from the first byte
int acc;
 
acc = i1 << 2; // six bits came from the first byte
acc |= i2 >> 4; // two bits came from the first byte
 
Line 331 ⟶ 330:
string data = "VG8gZXJyIGlzIGh1bWFuLCBidXQgdG8gcmVhbGx5IGZvdWwgdGhpbmdzIHVwIHlvdSBuZWVkIGEgY29tcHV0ZXIuCiAgICAtLVBhdWwgUi5FaHJsaWNo";
vector<ubyte> datav{ begin(data), end(data) };
cout << data << "\n\n" << decode(datav).data() << endl;
 
auto decoded = decode(datav);
std::for_each(cbegin(decoded), cend(decoded), [](char c) { cout << c; });
cout << '\n';
 
return 0;
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.