<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def base64_encode(data):
 """ Base 64 encoder """

    total = len(data)
    result = []
    mod = 0
    for i in range(total):
        cur = ord(data[i])
        mod = i % 3
        if mod == 0:
            result.append(__enc64__[cur >> 2])
        elif mod == 1:
            prev = ord(data[i - 1])
            result.append(__enc64__[((prev & 3) << 4) | (cur >> 4)])
        elif mod == 2:
            prev = ord(data[i - 1])
            result.append(__enc64__[(prev & 0x0f) << 2 | cur >> 6])
            result.append(__enc64__[cur & 0x3f])
    if mod == 0:
        result.append(__enc64__[(cur & 3) << 4])
        result.append(__enc64__[64] * 2)
    elif mod == 1:
        result.append(__enc64__[(cur & 0x0f) << 2])
        result.append(__enc64__[64])
    return "".join(result)