WALL-E/vin-decoder

vin验证码的计算

Closed this issue · 2 comments

提供公共的接口服务,或是示例代码

def check_sum(vincode):
    """
    checkout length, word and checksum
    """
    if not isinstance(vincode, str) and not isinstance(vincode, unicode):
        return False
    if len(vincode) != 17:
        return False

    vincode = vincode.upper()
    if "I" in vincode or "O" in vincode or "Q" in vincode:
        return False

    table = {
        "0": 0, "1": 1, "2": 2, "3": 3, "4": 4, "5": 5, "6": 6, "7": 7, "8": 8, "9": 9,
        "A": 1, "B": 2, "C": 3, "D": 4, "E": 5, "F": 6, "G": 7, "H": 8,
        "J": 1, "K": 2, "L": 3, "M": 4, "N": 5, "P": 7, "R": 9,
        "S": 2, "T": 3, "U": 4, "V": 5, "W": 6, "X": 7, "Y": 8, "Z": 9,
    }

    weight = [
        8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2
    ]

    total = 0
    for index, value in enumerate(vincode):
        try:
            tmp = table[value] * weight[index]
        except KeyError:
            break
        total = total + tmp

    remainder = total%11
    if remainder == 10:
        return vincode[8] == 'X'

    return str(remainder) == vincode[8]
车辆特征码,即vds(vehicle descriptor section)
有欧规与美规两种,美规是第4~8位;欧规是第4~9。**使用的是美规。

可见,校验码在极少数的场景下是不准确的