CCarryLoam
Workflows

Coding workflows · Odd-byte Internet checksums

03
Built around your work

A concrete starting point

Compute a 16-bit Internet checksum for zero to 65535 bytes, padding an odd final byte with zero. Test end-around carries and empty input, reject other types and keep this noncryptographic check separate from authentication.

01

Open the context

Choose the project folder and name the files or behavior involved.

02

Define the change

Describe the input, expected output and boundaries that must stay intact.

03

Inspect the work

Review the proposed edits and any commands before relying on their result.

04

Check the outcome

Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.

Odd-byte Internet checksums

A concrete starting point
def internet_checksum(data):
    if type(data) is not bytes or len(data) > 65535:
        raise ValueError("checksum.bytes")
    total = 0
    for i in range(0, len(data), 2):
        total += (data[i] << 8) | (data[i+1] if i+1 < len(data) else 0)
    while total >> 16:
        total = (total & 65535) + (total >> 16)
    return (~total) & 65535

The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.

AI coding workspace

Your next change starts here.

Get the Windows app ↗