diff options
| author | rPatrickWarner <[email protected]> | 2024-05-04 18:10:27 -0700 |
|---|---|---|
| committer | rPatrickWarner <[email protected]> | 2024-05-04 18:10:27 -0700 |
| commit | a6a32a3705fa04d7b52c301f7116c3a5705b854c (patch) | |
| tree | 1601ee9464203c5bbed6634364b5fb5914f007a5 /CST 126/Homework2/Base64Conversion.hpp | |
| parent | Added binary file reading function (diff) | |
| download | homework-1-reecepwarner-a6a32a3705fa04d7b52c301f7116c3a5705b854c.tar.xz homework-1-reecepwarner-a6a32a3705fa04d7b52c301f7116c3a5705b854c.zip | |
base64 encoding improvements
Diffstat (limited to 'CST 126/Homework2/Base64Conversion.hpp')
| -rw-r--r-- | CST 126/Homework2/Base64Conversion.hpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/CST 126/Homework2/Base64Conversion.hpp b/CST 126/Homework2/Base64Conversion.hpp index 3a87f70..9559467 100644 --- a/CST 126/Homework2/Base64Conversion.hpp +++ b/CST 126/Homework2/Base64Conversion.hpp @@ -1,7 +1,61 @@ #ifndef BASE64_CONVERSION_HPP #define BASE64_CONVERSION_HPP #include "Base64Helper.hpp" +#include <bitset> +#include <vector> +char CharacterMapArray[] = { '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', '/', '+'}; +inline char* Base64Encode(char* buffer, const size_t& size) +{ + size_t firstvalue, secondvalue, thirdvalue, fourthvalue = 0; + + char* TempBuff = new char[size]; + + + for (auto i = 0; i < size; i+=3) + { + + firstvalue = buffer[i] & 0x3f; + secondvalue = ((buffer[i] >> 6) ^ (buffer[i + 1] << 2)); + secondvalue &= 0x3f; + + thirdvalue = ((buffer[i + 1] >> 4) ^ (buffer[i + 2] << 4)); + thirdvalue &= 0x3f; + fourthvalue = (buffer[i + 2] >> 2); + fourthvalue &= 0x3f; + + + + + TempBuff[i] = CharacterMapArray[firstvalue]; + TempBuff[i + 1] = CharacterMapArray[secondvalue]; + TempBuff[i + 2] = CharacterMapArray[thirdvalue]; + TempBuff[i + 3] = CharacterMapArray[fourthvalue]; + } + delete[] buffer; + buffer = nullptr; + + buffer = new char[size]; + for (auto i = 0; i < size; i++) + { + buffer[i] = TempBuff[i]; + } + + + + //load the bytes into a block + //then and by 0x3f + //shift left by 6 + //then again + + return buffer; + +} + #endif
\ No newline at end of file |