MCPcopy Create free account
hub / github.com/S3N4T0R-0X0/PixelCode-Attack / Base64

Class Base64

payload.cpp:683–774  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

681#pragma comment(lib, "Ws2_32.lib")
682
683class Base64 {
684private:
685 static const std::string BASE64_CHARS;
686
687 static inline bool is_base64(unsigned char c) {
688 return (isalnum(c) || (c == '+') || (c == '/'));
689 }
690
691public:
692 static std::string encode(const std::string& input) {
693 std::string ret;
694 int i = 0;
695 unsigned char char_array_3[3], char_array_4[4];
696
697 for (size_t n = 0; n < input.size(); n++) {
698 char_array_3[i++] = input[n];
699 if (i == 3) {
700 char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
701 char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
702 char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
703 char_array_4[3] = char_array_3[2] & 0x3f;
704
705 for (i = 0; i < 4; i++) {
706 ret += BASE64_CHARS[char_array_4[i]];
707 }
708 i = 0;
709 }
710 }
711
712 if (i) {
713 for (int j = i; j < 3; j++) {
714 char_array_3[j] = '\0';
715 }
716
717 char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
718 char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
719 char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
720 char_array_4[3] = char_array_3[2] & 0x3f;
721
722 for (int j = 0; j < i + 1; j++) {
723 ret += BASE64_CHARS[char_array_4[j]];
724 }
725
726 while (i++ < 3) {
727 ret += '=';
728 }
729 }
730
731 return ret;
732 }
733
734 static std::string decode(const std::string& encoded_string) {
735 int in_len = encoded_string.size();
736 int i = 0;
737 int j = 0;
738 int in_ = 0;
739 unsigned char char_array_4[4], char_array_3[3];
740 std::string ret;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected