Skip to content

Simplify checksum code #152

@perexg

Description

@perexg

Hi, the checksum code used in the original Windows application is pretty simple:

        def checksum(msg):
            sum = 0x7f
            for byte in msg:
                for j in range(8):
                    sum <<= 1
                    if (byte & 0x80) == 0x80:
                        sum += 1
                    if (sum & 0x80) == 0x80:
                        sum ^= 0xa3
                    byte <<= 1
            return sum

        # binary message without trailing 0xFF
        if len(msg) > 1 and checksum(msg) != 0:
            raise SomeCheckSumError

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions