def _nih_checkdigit(h):
    """Luhn mod N algorithm in base 16 (hex) according to RFC6920_

    .. _RFC6920: https://www.ietf.org/rfc/rfc6920
    """
    factor = 2
    total = 0
    base = 16
    digits = len(h)
    parity = digits % 2
    for x in range(digits):
        digit = int(h[x], 16)
        if x % 2 != parity:
            digit *= 2
            total += sum(divmod(digit, 16))
        else:
            total += digit
    remainder = (16 - total) % 16
    return '%x' % remainder
