Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Module Name: BiteRepresent
- * Use: Converts a byte vector to a string and reverses.
- * Developer: Donkey Death Jam
- */
- #include "BiteRepresent.h"
- map<int, string> BiteRepresent::_NUMBERKEYMAP;
- map<string, int> BiteRepresent::_STRINGKEYMAP;
- void BiteRepresent::Initialize()
- {
- _NUMBERKEYMAP[0] = "A";
- _NUMBERKEYMAP[1] = "B";
- _NUMBERKEYMAP[2] = "C";
- _NUMBERKEYMAP[3] = "D";
- _NUMBERKEYMAP[4] = "E";
- _NUMBERKEYMAP[5] = "F";
- _NUMBERKEYMAP[6] = "G";
- _NUMBERKEYMAP[7] = "H";
- _NUMBERKEYMAP[8] = "I";
- _NUMBERKEYMAP[9] = "J";
- _STRINGKEYMAP["A"] = 0;
- _STRINGKEYMAP["B"] = 1;
- _STRINGKEYMAP["C"] = 2;
- _STRINGKEYMAP["D"] = 3;
- _STRINGKEYMAP["E"] = 4;
- _STRINGKEYMAP["F"] = 5;
- _STRINGKEYMAP["G"] = 6;
- _STRINGKEYMAP["H"] = 7;
- _STRINGKEYMAP["I"] = 8;
- _STRINGKEYMAP["J"] = 9;
- }
- string BiteRepresent::ByteToString(vector<BYTE> input)
- {
- string byteString;
- for (size_t i = 0; i < input.size(); i++)
- {
- string stringByte = to_string((int)input[i]);
- string stringRep = GetStringRepresentation(stringByte);
- byteString.append(stringRep + ":");
- }
- return byteString.substr(0, byteString.length() - 1);
- }
- vector<BYTE> BiteRepresent::StringToByte(string input)
- {
- vector<BYTE> bytes;
- vector<string> stringBytes = SplitString(input, ':');
- for (size_t i = 0; i < stringBytes.size(); i++)
- bytes.push_back(GetByteRepresentation(stringBytes[i]));
- return bytes;
- }
- string BiteRepresent::GetStringRepresentation(string input)
- {
- string rep;
- for (size_t i = 0; i < input.length(); i++)
- {
- string character(1, input[i]);
- int byteNum = stoi(character);
- if (_NUMBERKEYMAP.count(byteNum) > 0)
- rep.append(_NUMBERKEYMAP[byteNum]);
- }
- return rep;
- }
- BYTE BiteRepresent::GetByteRepresentation(string input)
- {
- string rep;
- for (size_t i = 0; i < input.length(); i++)
- {
- string character(1, input[i]);
- if (_STRINGKEYMAP.count(character) > 0)
- rep.append(to_string(_STRINGKEYMAP[character]));
- }
- return (BYTE)stoi(rep);
- }
- vector<string> BiteRepresent::SplitString(string text, char sep) {
- std::vector<std::string> tokens;
- std::size_t start = 0, end = 0;
- while ((end = text.find(sep, start)) != std::string::npos) {
- tokens.push_back(text.substr(start, end - start));
- start = end + 1;
- }
- tokens.push_back(text.substr(start));
- return tokens;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement