I was looking for a way to convert this string into base34 or base36 format.
I searched a lot, but everywhere I saw converting number to given base. Here, I am looking for a big string to encode.
So far, I tried following code:
Expand|Select|Wrap|Line Numbers
- char const c_base_encoding[] = "0123456789ABCDEFGHJKLMNPQRSTUVWXYZ";
- size_t const c_base_encoding_size = (sizeof(c_base_encoding)/sizeof(c_base_encoding[0])) - 1;
- std::string base_encode( unsigned __int8 * data, size_t size )
- {
- std::string encoded;
- unsigned long long value = 0;
- size_t tmp = sizeof(unsigned long long);
- for(size_t i = 0; i <= size; i+=tmp)
- {
- memcpy(&value, data+i,tmp);
- while( value > 0 )
- {
- encoded = c_base_encoding[ value % c_base_encoding_size ] + encoded;
- value /= c_base_encoding_size;
- }
- }
- return encoded;
- }
The problem is, final output should be 101 bytes, but its getting more than 400 bytes. I am missing something in here. Any idea? or do you suggest any other method? Reading long value out of byte array, is it a valid way of encoding?