алгоритм будет выглядеть примерно так:
1. Pad the input string to a multiple of 3 characters
2. Initialize an empty results array
3. Looping backwards in the input string taking 3 chars at a time
4. convert 3 chars to the 4 Base64 equivalent
5. unshift the Base64 string to the results array
6. Return the join of the results array.