```python
def line_tag(body: str) -> str:
    if not isinstance(body, str):
        raise ValueError("Body must be a string")
    tag = sum(ord(char) for char in body) % 256
    return f"{tag:02x}"


def check_line(line: str) -> str:
    if not isinstance(line, str):
        raise ValueError("Line must be a string")
    if len(line) < 3:
        raise ValueError("Line must be at least three characters long")
    body, tag = line[:-3], line[-3:]
    if body[-1] != '~':
        raise ValueError("Third-to-last character must be a tilde")
    expected_tag = line_tag(body)
    if expected_tag != tag:
        raise ValueError("Tag does not match the body")
    return body
```