Method code for $string.decode64()

[Turn off line numbering]
  1: arg enc_chars;
  2: var i, j, k, ints, out_buf, len, num, ob;
  3: 
  4: i = 1;
  5: out_buf = `[];
  6: len = enc_chars.length();
  7: while (i < len) {
  8:     refresh();
  9:     ints = [0, 0, 0, 0];
 10:     j = 1;
 11:     while (j <= 4) {
 12:         if (enc_chars[i] in base64str || enc_chars[i] == "=") {
 13:             for k in [1 .. 64] {
 14:                 refresh();
 15:                 if (strcmp(enc_chars[i], base64str[k]) == 0) {
 16:                     ints = replace(ints, j, (k - 1) % 64);
 17:                     break;
 18:                 }
 19:             }
 20:             j++;
 21:         }
 22:         i++;
 23:     }
 24:     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]];
 25: }
 26: return buf_to_str(out_buf);

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

Tlon