Base64.hpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2022-01-03
  6. * Changed: 2022-01-08
  7. *
  8. * */
  9. #ifndef LS_STD_BASE64_HPP
  10. #define LS_STD_BASE64_HPP
  11. #include <ls_std/encoding/IEncoding.hpp>
  12. #include <bitset>
  13. #include <vector>
  14. namespace ls_std
  15. {
  16. class Base64 : public ls_std::IEncoding
  17. {
  18. public:
  19. Base64() = default;
  20. ~Base64() = default;
  21. // implementation
  22. std::string encode(const std::string &_sequence) override;
  23. std::string decode(const std::string &_sequence) override;
  24. private:
  25. const std::vector<char> table
  26. {
  27. 'A','B','C','D','E','F','G','H',
  28. 'I','J','K','L','M','N','O','P',
  29. 'Q','R','S','T','U','V','W','X',
  30. 'Y','Z','a','b','c','d','e','f',
  31. 'g','h','i','j','k','l','m','n',
  32. 'o','p','q','r','s','t','u','v',
  33. 'w','x','y','z','0','1','2','3',
  34. '4','5','6','7','8','9','+','/'
  35. };
  36. static std::bitset<24> _getBitSequenceFromSequence(const std::string &basicString);
  37. static std::string _getEncodingFromSubSequence(const std::string& basicString);
  38. static std::string _getNextByteTriple(const std::string& _sequence, size_t index);
  39. };
  40. }
  41. #endif