def binb2b64(binarray)
      tab = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
      str = ''

      # for(var i = 0; i < binarray.length * 4; i += 3)
      i = 0
      while i < binarray.length * 4
        triplet = (((binarray[i >> 2].to_i >> 8 * (3 - i % 4)) & 0xFF) << 16) |
                     (((binarray[i + 1 >> 2].to_i >> 8 * (3 - (i + 1) % 4)) & 0xFF) << 8) |
                      ((binarray[i + 2 >> 2].to_i >> 8 * (3 - (i + 2) % 4)) & 0xFF)
        # for(var j = 0; j < 4; j++)
        j = 0
        while j < 4
          if i * 8 + j * 6 > binarray.length * 32
            str += $b64pad
          else
            str += tab[(triplet >> 6 * (3 - j)) & 0x3F].chr
          end
          j += 1
        end
        i += 3
      end
      str
    end
def binb2b64(binarray)
      tab = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
      str = ''

      # for(var i = 0; i < binarray.length * 4; i += 3)
      i = 0
      while i < binarray.length * 4
        triplet = (((binarray[i >> 2].to_i >> 8 * (3 - i % 4)) & 0xFF) << 16) |
                     (((binarray[i + 1 >> 2].to_i >> 8 * (3 - (i + 1) % 4)) & 0xFF) << 8) |
                      ((binarray[i + 2 >> 2].to_i >> 8 * (3 - (i + 2) % 4)) & 0xFF)
        # for(var j = 0; j < 4; j++)
        j = 0
        while j < 4
          if i * 8 + j * 6 > binarray.length * 32
            str += $b64pad
          else
            str += tab[(triplet >> 6 * (3 - j)) & 0x3F].chr
          end
          j += 1
        end
        i += 3
      end
      str
    end
Convert an array of big-endian words to a base-64 string