1 #include "../include/hex.h"
\r
10 static const std::string hexchars="0123456789ABCDEF";
\r
12 const bool Encode(const std::vector<unsigned char> &data, std::string &encoded)
\r
14 for(std::vector<unsigned char>::const_iterator i=data.begin(); i!=data.end(); i++)
\r
16 encoded.push_back(hexchars[(((*i)>>4) & 0x0F)]);
\r
17 encoded.push_back(hexchars[((*i) & 0x0F)]);
\r
22 const bool Decode(const std::string &encoded, std::vector<unsigned char> &data)
\r
25 std::string::size_type pos=0;
\r
29 pos=encoded.find_first_of(hexchars);
\r
31 while(pos!=std::string::npos)
\r
35 byte=(hexchars.find(encoded[pos]) << 4) & 0xF0;
\r
40 byte|=hexchars.find(encoded[pos]) & 0x0F;
\r
41 data.push_back(byte);
\r
44 pos=encoded.find_first_of(hexchars,pos+1);
\r