다음과 같이 Encoding 을 한다.
입력으로 Base64 Encoding 된 String 이 주어졌을 때, 해당 String 을 Decoding 하여, 원문을 출력하는 프로그램을 작성하시오.
[제약사항]
문자열의 길이는 항상 4의 배수로 주어진다.
그리고 문자열의 길이는 100000을 넘지 않는다.
[입력]
입력은 첫 줄에 총 테스트 케이스의 개수 T가 온다.
다음 줄부터 각 테스트 케이스가 주어진다.
테스트 케이스는 Encoding 된 상태로 주어지는 문자열이다.
[출력]
테스트 케이스 t에 대한 결과는 “#t”을 찍고, 한 칸 띄고, 정답을 출력한다.
(t는 테스트 케이스의 번호를 의미하며 1부터 시작한다.)
def decode_string(encoded_string):
base64_table = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
num = []
for i in encoded_string:
for j in base64_table:
if i == j:
num.append(base64_table.index(i))
binary = []
for i in num:
to_bin = bin(i)[2:].zfill(6)
binary.append(to_bin)
binary = ''.join(binary)
decode_bin = []
for i in range(0,len(binary),8):
decode_bin.append(binary[i:i+8])
sol = ''
for i in decode_bin:
sol += chr(int(i,2))
return sol
T = int(input())
# 여러개의 테스트 케이스가 주어지므로, 각각을 처리합니다.
for test_case in range(1, T + 1):
encoded_string = input()
print(f'#{test_case} {decode_string(encoded_string)}')