Base64 encode/decode functions

Find and share HowTos to various installations / configurations!
3 posts • Page 1 of 1
yosu
Posts:22
Joined: Wed Mar 14, 2012 4:14 pm

Base64 encode/decode functions

Post by yosu »

Maybe somebody needs it one day. Here you have a base64 encode/decode functions based on https://github.com/mathiasbynens/base64 ... /base64.js

Code: Select all

string UTILS_base64_encode(const string src)
{
  string basis_64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";

  int a, b, c, d;
  int position, padding, length, buffer;
  string output="";

  padding = strlen(src) % 3;
  position = -1;
  // Make sure any padding is handled outside of the loop.
  length = strlen(src) - padding;

  while (++position < length) {
        // Read three bytes, i.e. 24 bits.
        a = src[position]  18 & 0x3F)] + "" +
            basis_64[(buffer >> 12 & 0x3F)] + "" +
            basis_64[(buffer >> 6 & 0x3F)] + "" +
            basis_64[(buffer & 0x3F)]
        );
 	}

 	if (padding == 2) {
      a = src[position] > 10)] + "" +
               basis_64[((buffer >> 4) & 0x3F)] + "" +
               basis_64[((buffer > 2)] + "" + basis_64[((buffer > (-2 * bitCounter & 6);
      output += c;
    }
  }
  return output;
}

Gertjan van Schijndel
Posts:634
Joined: Mon Aug 02, 2010 10:37 am

Re: Base64 encode/decode functions

Post by Gertjan van Schijndel »

What are the benefits of these functions over the standard base64Encode/base64Decode?

At the first glance I see that these functions are not able to handle 0-characters.

yosu
Posts:22
Joined: Wed Mar 14, 2012 4:14 pm

Re: Base64 encode/decode functions

Post by yosu »

On version 3.14 I can not find base64Encode/Decode, that is because I made it. And sure this functions can be made better, of course.

3 posts • Page 1 of 1