Skip to content

Wrong checksum for ISSN #238

@mezzelfo

Description

@mezzelfo

I think the current implementation of _calculate_checksum in InternationalStandardSerialNumber is wrong. Indeed, the tmp variable sometimes assume the value of "11", while should probably be "0", making the checksum two digits long!

This is a minimum replicating example:

from barcode import ISSN
print(ISSN("6727893").issn) # output = 672789311 when should be 67278930

Simply adding and extra %11 operation at the end of the tmp computation should solve the issue:

def _calculate_checksum(self):
    tmp = (
        11
        - sum(x * int(y) for x, y in enumerate(reversed(self.issn[:7]), start=2))
        % 11
    ) % 11
    if tmp == 10:
        return "X"

    return tmp

For reference:

def _calculate_checksum(self):

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions