___ ___ ____ _ ___ _ _
| | / ___| | _ \ | | / | | | | |
| /| | \ `--. | |_) | | | / /| | | |__| |
| ___| `--. \ | _ < | | / / | | | __ |
| | /\__/ | |_) | | |___ / ___ | | | | |
|_| \____/ |____/ |_____| \/ |_| |_| |_|import os
import hashlib
# βββ the entombed residue ββββββββββββββββββββββββββββββββββββββββββββββββ
_Ξ© = 0x5a0f97d7dc14b54ae798048d5599dddc0053f16ff93e11a7db1c78965535ac0f129c00c95637a43da2f0e0b2d54b9cd04a32b7059ec45ad9618bf1c45ea2f97258f579c9c315e730a03c3e5426c9f8bc231a267b66913e84db2af9e169d6261e9d41d5136e6d
_Ξ = 819 # exact bit-length of the residue
_Ξ£ = "a0d6c7136a9598d910bf00f6d297f5c04af277c6b3a2ee8a5164caaf1038ca40"
_Ξ¦ = 0x9E3779B97F4A7C15 # βΟΒ·2βΆβ΄β β the keystream germ
_Ξ€ = 0xD800000000000000 # taps of xβΆβ΄+xβΆΒ³+xβΆΒΉ+xβΆβ°+1 (maximal period)
def _keystream(Ο=_Ξ¦):
while True:
yield Ο & 1
Ο = (Ο >> 1) ^ (-(Ο & 1) & _Ξ€)
class _Scry:
__slots__ = ("_ptr",)
def __init__(self):
self._ptr = 0
def __matmul__(self, n):
if self._ptr + n > _Ξ:
raise EOFError("scried past the edge of the residue")
v = (_Ξ© >> (_Ξ - self._ptr - n)) & ((1 << n) - 1)
self._ptr += n
return v
def _spin(thunk):
while callable(thunk):
thunk = thunk()
return thunk
class _Rite(type):
def __new__(mcls, name, bases, ns):
cls = super().__new__(mcls, name, bases, ns)
cls._corpus = mcls._exhume()
if hashlib.sha256(cls._corpus).hexdigest() != _Ξ£:
raise RuntimeError("the seal is broken; these glyphs are lies")
return cls
@staticmethod
def _exhume():
s = _Scry()
P = s @ 8
palette = bytes(s @ 7 for _ in range(P))
lens = [s @ 4 for _ in range(P)]
N = s @ 20
M = 0
for l in lens:
M = l if l > M else M
cnt = [0] * (M + 1)
for l in lens:
cnt[l] += 1
first = [0] * (M + 1)
index = [0] * (M + 1)
c = t = 0
for l in range(1, M + 1):
c = (c + cnt[l - 1]) << 1
t += cnt[l - 1]
first[l] = c
index[l] = t
ks = _keystream()
out = bytearray()
def step(code, l, got):
if got == N:
return bytes(out)
code = (code << 1) | ((s @ 1) ^ next(ks))
l += 1
if l <= M and cnt[l] and first[l] <= code < first[l] + cnt[l]:
out.append(palette[index[l] + code - first[l]])
return lambda: step(0, 0, got + 1)
if l > M:
raise RuntimeError("wandered off the edge of the tree")
return lambda: step(code, l, got)
return _spin(lambda: step(0, 0, 0))
class Sigil(metaclass=_Rite):
__slots__ = ()
def __call__(self):
os.write(1, type(self)._corpus)
if __name__ == "__main__":
Sigil()()


