```python
def mask_from_prefix(prefix: int) -> str:
    if isinstance(prefix, bool) or 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")
    
    parts = mask.split(".")
    if len(parts) != 4:
        raise ValueError("mask must have exactly four octets separated by dots")
    
    ones_count = 0
    for part in parts:
        if not part.isdigit():
            raise ValueError("each octet must contain only decimal digits")
        
        value = int(part)
        if value < 0 or value > 255:
            raise ValueError("each octet must be between 0 and 255 inclusive")
        
        if value > 0 and ones_count == 0:
            ones_count += 8
        elif value < 255 and ones_count != 8:
            raise ValueError("one bits must be unbroken by a zero")
        else:
            ones_count -= min(ones_count, 8)
    
    return 32 - ones_count
```