// base64.js

var hexBinChars = "0123456789ABCDEF";

function hexBinEncode(arrBytes)
{
    var out, i, len;

    len = arrBytes.length;
    out = "";
    for(i = 0; i < len; i++)
    {
	var b = (arrBytes[i] >> 4);
	out += hexBinChars.charAt(b);
	b = (arrBytes[i] & 0x0F);
	out += hexBinChars.charAt(b);
    }
    return out;
}

function hexBinDecode(str)
{
    var i, j, len;

    len = str.length / 2;
    var arrData = new Array(len);
    j = 0;
    for (i = 0; i < len; i++)
    {
	var offset = hexBinChars.search(str.charAt(j++));
	if (offset == -1)
	{
	    continue;
	}
	var c = (offset << 4);
        offset = hexBinChars.search(str.charAt(j++));
	if (offset == -1)
	{
	    continue;
	}
        arrData[i] = (c | offset);
    }
    return arrData;
}
