All problems
Base64 Encode
Problem
Encode a string to standard base64 using the alphabet A through Z, a through z, 0 through 9, plus and slash, with equals-sign padding.
Each group of three bytes becomes four characters; a final group of one or two bytes uses two or three characters plus padding. The empty string encodes to the empty string.
Hint
Pack three bytes into a 24-bit number and read it back six bits at a time.
Test cases
case 1
in: ["hello"]
expected: "aGVsbG8="
case 2
in: [""]
expected: ""
case 3
in: ["a"]
expected: "YQ=="
case 4
in: ["ab"]
expected: "YWI="
case 5
in: ["abc"]
expected: "YWJj"
case 6
in: ["Man"]
expected: "TWFu"
Starter codePython
def base64_encode(data):
# Your code here
pass6 test cases · run your code against them in the editor