def hotp(key, counter, digits=6):
    """
    These test vectors come from RFC-4226
    (https://tools.ietf.org/html/rfc4226#page-32).

    >>> key = b'12345678901234567890'
    >>> for c in range(10):
    ...     hotp(key, c)
    '755224'
    '287082'
    '359152'
    '969429'
    '338314'
    '254676'
    '287922'
    '162583'
    '399871'
    '520489'
    """

    msg = struct.pack('>Q', counter)
    hs = hmac.new(key, msg, hashlib.sha1).digest()
    offset = six.indexbytes(hs, 19) & 0x0f
    val = struct.unpack('>L', hs[offset:offset + 4])[0] & 0x7fffffff
    return '{val:0{digits}d}'.format(val=val % 10 ** digits, digits=digits)