|
@@ -12,12 +12,12 @@
|
|
|
|
|
|
std::string ls_std::Base64::encode(const std::string &_sequence)
|
|
|
{
|
|
|
- std::string encodedString, byteTriple{};
|
|
|
+ std::string encodedString{};
|
|
|
|
|
|
for(size_t index = 0 ; index < _sequence.size() ; index += 3)
|
|
|
{
|
|
|
- byteTriple = ls_std::Base64::_getNextByteTriple(_sequence, index);
|
|
|
- encodedString += ls_std::Base64::_getEncodingFromByteTriple(byteTriple);
|
|
|
+ std::string byteTriple = ls_std::Base64::_getNextByteTriple(_sequence, index);
|
|
|
+ encodedString += ls_std::Base64::_encodeByteTriple(byteTriple);
|
|
|
}
|
|
|
|
|
|
return encodedString;
|
|
@@ -55,9 +55,11 @@ std::string ls_std::Base64::_decodeByteQuadruple(const std::string& _quadruple)
|
|
|
return decodedText;
|
|
|
}
|
|
|
|
|
|
-uint8_t ls_std::Base64::_detectInitialShiftNumber(size_t size)
|
|
|
+std::string ls_std::Base64::_encodeByteTriple(const std::string& characterSequence)
|
|
|
{
|
|
|
- return size * 8 - 6;
|
|
|
+ std::string encodedText{};
|
|
|
+
|
|
|
+ return encodedText;
|
|
|
}
|
|
|
|
|
|
uint32_t ls_std::Base64::_extractBitSequence(uint32_t _bitMask, uint32_t _bitStorage)
|
|
@@ -80,68 +82,43 @@ uint32_t ls_std::Base64::_generateBitMask(uint32_t _maskValue, uint8_t _shiftVal
|
|
|
return _maskValue << _shiftValue;
|
|
|
}
|
|
|
|
|
|
-std::string ls_std::Base64::_getEncodingFromBitSequence(uint32_t bitSequence, size_t characterSequenceSize)
|
|
|
+std::unordered_map<char, uint8_t> ls_std::Base64::_getDecodingMap()
|
|
|
{
|
|
|
- std::string encodedString{};
|
|
|
- uint8_t shiftByBits = ls_std::Base64::_detectInitialShiftNumber(characterSequenceSize);
|
|
|
- uint32_t buffer;
|
|
|
-
|
|
|
- for (uint8_t index = 0 ; index < 3 ; index++)
|
|
|
+ static std::unordered_map<char, uint8_t> decodingMap =
|
|
|
{
|
|
|
- buffer = bitSequence >> shiftByBits;
|
|
|
- encodedString += this->_getCharacterFromLookUpTable((uint8_t) buffer);
|
|
|
- shiftByBits -= 6;
|
|
|
- }
|
|
|
+ {'A', 0}, {'B', 1}, {'C', 2}, {'D', 3}, {'E', 4}, {'F', 5}, {'G', 6}, {'H', 7},
|
|
|
+ {'I', 8}, {'J', 9}, {'K', 10}, {'L', 11}, {'M', 12}, {'N', 13}, {'O', 14}, {'P', 15},
|
|
|
+ {'Q', 16}, {'R', 17}, {'S', 18}, {'T', 19}, {'U', 20}, {'V', 21}, {'W', 22}, {'X', 23},
|
|
|
+ {'Y', 24}, {'Z', 25}, {'a', 26}, {'b', 27}, {'c', 28}, {'d', 29}, {'e', 30}, {'f', 31},
|
|
|
+ {'g', 32}, {'h', 33}, {'i', 34}, {'j', 35}, {'k', 36}, {'l', 37}, {'m', 38}, {'n', 39},
|
|
|
+ {'o', 40}, {'p', 41}, {'q', 42}, {'r', 43}, {'s', 44}, {'t', 45}, {'u', 46}, {'v', 47},
|
|
|
+ {'w', 48}, {'x', 49}, {'y', 50}, {'z', 51}, {'0', 52}, {'1', 53}, {'2', 54}, {'3', 55},
|
|
|
+ {'4', 56}, {'5', 57}, {'6', 58}, {'7', 59}, {'8', 60}, {'9', 61}, {'+', 62}, {'/', 63}
|
|
|
+ };
|
|
|
|
|
|
- return encodedString;
|
|
|
+ return decodingMap;
|
|
|
}
|
|
|
|
|
|
-uint32_t ls_std::Base64::_getBitSequenceFromCharacterSequence(const std::string &basicString)
|
|
|
+std::vector<char> ls_std::Base64::_getEncodingField()
|
|
|
{
|
|
|
- uint32_t bits{};
|
|
|
-
|
|
|
- for (const char &letter : basicString)
|
|
|
+ static std::vector<char> encodingTable
|
|
|
{
|
|
|
- bits = bits | (uint8_t) letter;
|
|
|
- bits = bits << 8;
|
|
|
- }
|
|
|
-
|
|
|
- bits = bits >> 8;
|
|
|
- return bits;
|
|
|
-}
|
|
|
-
|
|
|
-char ls_std::Base64::_getCharacterFromLookUpTable(uint8_t byteBuffer)
|
|
|
-{
|
|
|
- std::bitset<8> bitSequence{byteBuffer};
|
|
|
- bitSequence.set(6, false);
|
|
|
- bitSequence.set(7, false);
|
|
|
-
|
|
|
- return this->encodingTable[bitSequence.to_ulong()];
|
|
|
+ 'A','B','C','D','E','F','G','H',
|
|
|
+ 'I','J','K','L','M','N','O','P',
|
|
|
+ 'Q','R','S','T','U','V','W','X',
|
|
|
+ 'Y','Z','a','b','c','d','e','f',
|
|
|
+ 'g','h','i','j','k','l','m','n',
|
|
|
+ 'o','p','q','r','s','t','u','v',
|
|
|
+ 'w','x','y','z','0','1','2','3',
|
|
|
+ '4','5','6','7','8','9','+','/'
|
|
|
+ };
|
|
|
+
|
|
|
+ return encodingTable;
|
|
|
}
|
|
|
|
|
|
-std::unordered_map<char, uint8_t> ls_std::Base64::_getDecodingMap()
|
|
|
-{
|
|
|
- static std::unordered_map<char, uint8_t> decodingMap =
|
|
|
- {
|
|
|
- {'A', 0}, {'B', 1}, {'C', 2}, {'D', 3}, {'E', 4}, {'F', 5}, {'G', 6}, {'H', 7},
|
|
|
- {'I', 8}, {'J', 9}, {'K', 10}, {'L', 11}, {'M', 12}, {'N', 13}, {'O', 14}, {'P', 15},
|
|
|
- {'Q', 16}, {'R', 17}, {'S', 18}, {'T', 19}, {'U', 20}, {'V', 21}, {'W', 22}, {'X', 23},
|
|
|
- {'Y', 24}, {'Z', 25}, {'a', 26}, {'b', 27}, {'c', 28}, {'d', 29}, {'e', 30}, {'f', 31},
|
|
|
- {'g', 32}, {'h', 33}, {'i', 34}, {'j', 35}, {'k', 36}, {'l', 37}, {'m', 38}, {'n', 39},
|
|
|
- {'o', 40}, {'p', 41}, {'q', 42}, {'r', 43}, {'s', 44}, {'t', 45}, {'u', 46}, {'v', 47},
|
|
|
- {'w', 48}, {'x', 49}, {'y', 50}, {'z', 51}, {'0', 52}, {'1', 53}, {'2', 54}, {'3', 55},
|
|
|
- {'4', 56}, {'5', 57}, {'6', 58}, {'7', 59}, {'8', 60}, {'9', 61}, {'+', 62}, {'/', 63}
|
|
|
- };
|
|
|
-
|
|
|
- return decodingMap;
|
|
|
-}
|
|
|
-
|
|
|
-std::string ls_std::Base64::_getEncodingFromByteTriple(const std::string& characterSequence)
|
|
|
+std::string ls_std::Base64::_getNextByteQuadruple(const std::string &_sequence, size_t _index)
|
|
|
{
|
|
|
- uint32_t bitSequence = ls_std::Base64::_getBitSequenceFromCharacterSequence(characterSequence);
|
|
|
- std::string encodingString = this->_getEncodingFromBitSequence(bitSequence, characterSequence.size());
|
|
|
-
|
|
|
- return encodingString;
|
|
|
+ return _sequence.substr(_index, 4);
|
|
|
}
|
|
|
|
|
|
std::string ls_std::Base64::_getNextByteTriple(const std::string &_sequence, size_t _index)
|
|
@@ -149,11 +126,6 @@ std::string ls_std::Base64::_getNextByteTriple(const std::string &_sequence, siz
|
|
|
return _sequence.substr(_index, 3);
|
|
|
}
|
|
|
|
|
|
-std::string ls_std::Base64::_getNextByteQuadruple(const std::string &_sequence, size_t _index)
|
|
|
-{
|
|
|
- return _sequence.substr(_index, 4);
|
|
|
-}
|
|
|
-
|
|
|
void ls_std::Base64::_mergeBitSequence(uint32_t &_bitStorage, const uint32_t &_bitMask)
|
|
|
{
|
|
|
_bitStorage = _bitStorage | _bitMask;
|