Method code for $string.decode64()

[Turn on line numbering]
arg enc_chars;
var i, j, k, ints, out_buf, len, num, ob;

i = 1;
out_buf = `[];
len = enc_chars.length();
while (i < len) {
    refresh();
    ints = [0, 0, 0, 0];
    j = 1;
    while (j <= 4) {
        if (enc_chars[i] in base64str || enc_chars[i] == "=") {
            for k in [1 .. 64] {
                refresh();
                if (strcmp(enc_chars[i], base64str[k]) == 0) {
                    ints = replace(ints, j, (k - 1) % 64);
                    break;
                }
            }
            j++;
        }
        i++;
    }
    out_buf = out_buf + `[ints[1].shleft(2) % 256 + ints[2].shright(4), ints[2].shleft(4) % 256 + ints[3].shright(2), ints[3].shleft(6) % 256 + ints[4]];
}
return buf_to_str(out_buf);

// Created 27-Mar-1995 as a part of ColdCore, see: @help Credit

Tlon