|
@@ -3,11 +3,13 @@
|
|
|
* Company: Lynar Studios
|
|
|
* E-Mail: webmaster@lynarstudios.com
|
|
|
* Created: 2022-01-03
|
|
|
- * Changed: 2022-01-03
|
|
|
+ * Changed: 2022-01-08
|
|
|
*
|
|
|
* */
|
|
|
|
|
|
#include <ls_std/encoding/base64/Base64.hpp>
|
|
|
+#include <bitset>
|
|
|
+#include <sstream>
|
|
|
|
|
|
std::string ls_std::Base64::encode(const std::string &_sequence)
|
|
|
{
|
|
@@ -15,8 +17,8 @@ std::string ls_std::Base64::encode(const std::string &_sequence)
|
|
|
|
|
|
for(size_t index = 0 ; index < _sequence.size() ; index += 3)
|
|
|
{
|
|
|
- subSequence = ls_std::Base64::_getSubSequence(_sequence, index);
|
|
|
- encodedString +=
|
|
|
+ subSequence = ls_std::Base64::_getNextByteTriple(_sequence, index);
|
|
|
+ encodedString += ls_std::Base64::_getEncodingFromSubSequence(subSequence);
|
|
|
}
|
|
|
|
|
|
return encodedString;
|
|
@@ -27,19 +29,38 @@ std::string ls_std::Base64::decode(const std::string &_sequence)
|
|
|
return "";
|
|
|
}
|
|
|
|
|
|
-std::string ls_std::Base64::_getSubSequence(const std::string &_sequence, size_t index)
|
|
|
+std::bitset<24> ls_std::Base64::_getBitSequenceFromSequence(const std::string &basicString)
|
|
|
+{
|
|
|
+ uint32_t bits{};
|
|
|
+ std::stringstream stringStream{basicString};
|
|
|
+ stringStream >> bits;
|
|
|
+ std::bitset<32> bitSequenceBuffer{bits};
|
|
|
+ std::bitset<24> bitSequence{};
|
|
|
+
|
|
|
+ return bitSequence;
|
|
|
+}
|
|
|
+
|
|
|
+std::string ls_std::Base64::_getEncodingFromSubSequence(const std::string& basicString)
|
|
|
+{
|
|
|
+ std::string encodingString{};
|
|
|
+ std::bitset<24> bitSequence = ls_std::Base64::_getBitSequenceFromSequence(basicString);
|
|
|
+
|
|
|
+ return encodingString;
|
|
|
+}
|
|
|
+
|
|
|
+std::string ls_std::Base64::_getNextByteTriple(const std::string &_sequence, size_t index)
|
|
|
{
|
|
|
std::string subSequence{_sequence[index]};
|
|
|
size_t size = _sequence.size();
|
|
|
|
|
|
if((index + 1) < size)
|
|
|
{
|
|
|
- subSequence += (_sequence[size+1]);
|
|
|
+ subSequence += (_sequence[index+1]);
|
|
|
}
|
|
|
|
|
|
if((index + 2) < size)
|
|
|
{
|
|
|
- subSequence += (_sequence[size+2]);
|
|
|
+ subSequence += (_sequence[index+2]);
|
|
|
}
|
|
|
|
|
|
return subSequence;
|