Atelier des rouesLab FR
Objects/Documentation

flux11.py

I provide this item to reproduce or inspect AT.COD3.

Download ↓
"""Exact round-trip KT binary reference with a length header and byte termination."""
from pathlib import Path
from hashlib import sha256
import json,zlib

def bounds(n):
    return 1 << (n*8+(8*n+2).bit_length()+16)

def encode(raw):
    n=len(raw);end=bounds(n);start=0;zero=one=1
    for byte in raw:
        for shift in reversed(range(8)):
            split=start+(end-start)*zero//(zero+one)
            if not start<split<end:raise ArithmeticError("exhausted fixed-precision budget")
            if byte>>shift&1:start=split;one+=2
            else:end=split;zero+=2

Read in context

Comments

Comments from both language editions appear here.

The discussion is open for reading. I’ll enable submissions once spam protection is configured.