use binary.pkg define C_base64EncodeChars for "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=" Class cBase64 is a cObject function CharCodeAt variant vStr integer iPos returns UChar function_return (ascii(mid(vStr, 1, iPos))) end_function function CharAt variant vStr integer iPos returns string function_return (mid(vStr, 1, iPos)) end_function function base64Encode variant sIn returns string string sOut integer i iLen UChar c1 c2 c3 Char ndx1 ndx2 ndx3 ndx4 move (length(sIn)) to iLen move 1 to i while (i <= iLen) move (rshift((CharCodeAt(self, &sIn, i) IAND $FC), 2)) to ndx1 move (lshift((CharCodeAt(self, &sIn, i) IAND $03), 4)) to ndx2 add 1 to i if (i <= iLen) begin move ((rshift((CharCodeAt(self, &sIn, i) IAND $F0), 4) IOR ndx2)) to ndx2 move (lshift((CharCodeAt(self, &sIn, i) IAND $0F), 2)) to ndx3 add 1 to i if (i <= iLen) begin move ((rshift((CharCodeAt(self, &sIn, i) IAND $C0), 6) IOR ndx3)) to ndx3 move (CharCodeAt(self, &sIn, i) IAND $3F) to ndx4 add 1 to i end else move 64 to ndx4 end else begin move 64 to ndx3 move 64 to ndx4 end move (sOut + CharAt(self, C_base64EncodeChars, ndx1+1)) to sOut move (sOut + CharAt(self, C_base64EncodeChars, ndx2+1)) to sOut move (sOut + CharAt(self, C_base64EncodeChars, ndx3+1)) to sOut move (sOut + CharAt(self, C_base64EncodeChars, ndx4+1)) to sOut end function_return sOut end_function function base64Decode string sIn returns string string sOut integer i iLen integer c1 c2 c3 Char ndx1 ndx2 ndx3 ndx4 move (length(sIn)) to iLen move 1 to i while (i <= iLen) move 64 to ndx1 move 64 to ndx2 move 64 to ndx3 move 64 to ndx4 move (pos(charAt(self, &sIn, i), C_base64EncodeChars)-1) to ndx1 add 1 to i if (i <= iLen) begin move (pos(charAt(self, &sIn, i), C_base64EncodeChars)-1) to ndx2 add 1 to i if (i <= iLen) begin move (pos(charAt(self, &sIn, i), C_base64EncodeChars)-1) to ndx3 add 1 to i if (i <= iLen) begin move (pos(charAt(self, &sIn, i), C_base64EncodeChars)-1) to ndx4 add 1 to i end end end if (ndx4 = 64) move 0 to ndx4 if (ndx3 = 64) move 0 to ndx3 if (ndx2 = 64) move 0 to ndx2 move (lshift(ndx1, 2) ior rshift(ndx2, 4)) to c1 move (lshift(ndx2, 4) ior rshift(ndx3, 2)) to c2 move (lshift(ndx3, 6) ior ndx4) to c3 move (sOut + character(c1) + character(c2) + character(c3)) to sOut end function_return sOut end_function end_class object oBase64 is a cBase64 end_object