identique / idnumbers

idnumbers: Unlocking the power of national ID numbers
https://identique.github.io/idnumbers/
MIT License
12 stars 3 forks source link

[BUG] TWN country issue #276

Open lijiachang opened 1 year ago

lijiachang commented 1 year ago

Describe the bug TWN.NationalID.checksum method may be return 10

    @staticmethod
    def checksum(id_number) -> Optional[CHECK_DIGIT]:
        """
        algorithm:
        https://zh.wikipedia.org/wiki/%E4%B8%AD%E8%8F%AF%E6%B0%91%E5%9C%8B%E5%9C%8B%E6%B0%91%E8%BA%AB%E5%88%86%E8%AD%89#%E6%9C%89%E6%95%88%E7%A2%BC
        """
        if not validate_regexp(id_number, NationalID.METADATA.regexp):
            return False
        # it uses modulus 10 algorithm with magic numbers
        location = id_number[0]
        numbers = NationalID.LOCATION_NUM[ord(location) - 65] + [int(char) for char in id_number[1:]]
        modulus = weighted_modulus_digit(numbers[:-1], NationalID.MAGIC_MULTIPLIER, 10)
        return modulus

weighted_modulus_digit :The function may actually return a 10 instead of being in the range 0~9

lijiachang commented 1 year ago

Example: validate id: M162773050

from idnumbers.nationalid import TWN
id_number = "M162773050"
print(id_number, ' -> ', TWN.NationalID.validate(id_number))

result is: M162773050 -> False

In fact, this ID is correct