Compared against declared_pairs · told 12 of 12 deliberately broken copies apart · 2004 ms
def keep(ch):
if ch == ' ':
return 0
if ch == '\n':
return 0
if ch == '\r':
return 0
if ch == '\t':
return 0
if ch == '=':
return 0
if ch == '\f':
return 0
return 1
def val(ch):
alpha = 'ABCDEFGHIJKLMNOP' + 'QRSTUVWXYZ' + 'abcdefghijklmnop' + 'qrstuvwxyz' + '0123456789' + '+/'
i = 0
for u in alpha:
if ch == u:
return i
i = i + 1
return -1
def byte_char(n):
if n == 10:
return '\n'
if n == 13:
return '\r'
if n == 9:
return '\t'
chars = ' !"#' + "%&'()*+,-./0" + '123456789:;' + '<' + '=' + '>' + '?@' + 'ABCDEFGHIJKLMNOP' + 'QRSTUVWXYZ[\\]^_`' + 'abcdefghijklmnop' + 'qrstuvwxyz{|}~'
i = 0
nchars = len(chars)
while i < nchars:
code = 32 + i
if i > 3:
code = 33 + i
if code == n:
return chars[i]
i = i + 1
return ''
def solve(s):
vals = []
for ch in s:
if keep(ch) == 1:
v = val(ch)
if v > -1:
vals = vals + [v]
out = ''
i = 0
n = len(vals)
while i + 1 < n:
v0 = vals[i]
v1 = vals[i + 1]
have = 2
v2 = 0
v3 = 0
if i + 2 < n:
v2 = vals[i + 2]
have = 3
if i + 3 < n:
v3 = vals[i + 3]
have = 4
b0 = v0 * 4 + (v1 // 16)
b1 = (v1 % 16) * 16 + (v2 // 4)
b2 = (v2 % 4) * 64 + v3
out = out + byte_char(b0)
if have > 2:
out = out + byte_char(b1)
if have > 3:
out = out + byte_char(b2)
if have < 4:
i = n
else:
i = i + 4
return out
12 test cases ship with it; the first three:
| in | out |
|---|---|
dzn kkwvzw dzn umva 0 | w9k |
cpdiv wrlnqq cpdiv sgstj 1 | rb - |
swrfw qsgagb swrfw pahm 2 | jf |
GET https://research.zaiba.cloud/api/v1/programs/base64_decode
POST https://research.zaiba.cloud/api/v1/programs/base64_decode/run
{"input": "…"}
# 200 · X-DeAI-Rail: grant (free within the allowance) · output + signed receipt
GET https://research.zaiba.cloud/api/v1/programs/base64_decode/code
# 200 · text/plain · the tool as one Python file, written by the library's authors