D2
다음과 같이 Encoding 을 한다.
우선 24비트 버퍼에 위쪽(MSB)부터 한 byte씩 3 byte의 문자를 집어넣는다.
버퍼의 위쪽부터 6비트씩 잘라 그 값을 읽고, 각각의 값을 아래의 문자로 Encoding 한다.

입력으로 Base64 Encoding 된 String 이 주어졌을 때, 해당 String 을 Decoding 하여, 원문을 출력하는 프로그램을 작성하시오.
[제약사항]
문자열의 길이는 항상 4의 배수로 주어진다.
그리고 문자열의 길이는 100000을 넘지 않는다.
SWEA에는 base64 라이브러리 사용이 막혀 있다.
from base64 import b64decode
T = int(input())
encode_list = []
for _ in range(T):
encode_string = input()
encode_list.append(encode_string)
for t, encode_string in enumerate(encode_list, start=1):
print("#", t, end=" ")
decode_string = base64.b64decode(encode_string.encode('utf-8'))
decode_string = decode_string.decode('utf-8')
print(decode_string)
T = int(input())
encode_list = []
decode = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
'0','1','2','3','4','5','6','7','8','9','+','/']
for _ in range(T):
encode_string = input()
encode_list.append(encode_string)
for t, encode_string in enumerate(encode_list, start=1):
print("#"+str(t), end=" ")
decode_string = ""
# 1. base64 문자열 -> 10진수
for c, char in enumerate(encode_string, start=0):
index = decode.index(char)
# 2. 10진수 -> 이진수 변환
binary = bin(index)[2:]
if len(binary)<6:
binary = "0"*(6-len(binary)) + binary
decode_string += binary
# 3. 이진수 -> 바이트 전환
decode_string = bytes([int(decode_string[j:j+8], 2) for j in range(0, len(decode_string), 8)])
decoded_text = decode_string.decode('utf-8')
# 4. 출력
print(decoded_text)