def make_alphabet(): chars = [chr(i) for i in range(ord('ก'), ord('ก') + 47)] # ก... (47 ตัว) chars += [chr(i) for i in range(ord('๐'), ord('๐') + 10)] # ๐-๙ (10 ตัว) chars += [chr(i) for i in range(ord('0'), ord('0') + 10)] # 0-9 (10 ตัว) return chars[:64] ALPHABET = make_alphabet() ALPH2VAL = {c: i for i, c in enumerate(ALPHABET)} def custom64_to_int(s): value = 0 for ch in s: if ch not in ALPH2VAL: raise ValueError(f"Alphabet NOT FOUND IN: {ch!r}") value = value * 64 + ALPH2VAL[ch] return value def decode_custom_base64(enc_text): if enc_text.endswith("=="): enc_text = enc_text[:-2] n = custom64_to_int(enc_text) hex_str = format(n, "x") if len(hex_str) % 2 == 1: hex_str = "0" + hex_str data = bytes.fromhex(hex_str) return data.decode("utf-8", errors="replace") if __name__ == "__main__": import pathlib enc_path = pathlib.Path("enc.txt") enc_text = enc_path.read_text(encoding="utf-16").strip() result = decode_custom_base64(enc_text) print(result)