```python
def mask_from_prefix(prefix: int) -> str:
    if not isinstance(prefix, int) or not 0 <= prefix <= 32:
        raise ValueError("prefix must be an integer from 0 to 32")
    octets = []
    for slot in range(4):
        ones = min(8, max(0, prefix - slot * 8))
        octets.append(str(256 - 2 ** (8 - ones)))
    return ".".join(octets)


    
def prefix_from_mask(mask: str) -> int:
    if not isinstance(mask, str):
        raise ValueError("mask must be a string")
    octets = mask.split(".")
    if len(octets) !=        raise ValueError("mask must have exactly four dot-separated fields")
       for octet in octets:
        if not octet.isdigit() or 
            raise ValueError("each field must hold decimal digits")
        if octet.startswith('0') and len(octet) > 1):
            raise ValueError("a field cannot have a leading zero other than 0 itself")
        if not 0 <= int(octet) <= 255:
            raise ValueError("an octet must hold between 0 and 255")
    leading_ones =    count = 0
    for octet in octets:
        if int(octet) == 255:
            count +=        elif int(octet) == 0:
                break
            else:
                raise ValueError("ones bits are broken by a zero")
        leading_ones += count
    return leading_ones
```