#NEWLINE# def hotp( key , counter , digits = 6 ) : #NEWLINE# #INDENT# "\n    These test vectors come from RFC-4226\n    (https://tools.ietf.org/html/rfc4226#page-32).\n\n    >>> key = b'12345678901234567890'\n    >>> for c in range(10):\n    ...     hotp(key, c)\n    '755224'\n    '287082'\n    '359152'\n    '969429'\n    '338314'\n    '254676'\n    '287922'\n    '162583'\n    '399871'\n    '520489'\n    " #NEWLINE# msg = struct . pack ( '>Q' , counter ) #NEWLINE# hs = hmac . new ( key , msg , hashlib . sha1 ) . digest ( ) #NEWLINE# offset = ( six . indexbytes ( hs , 19 ) & 15 ) #NEWLINE# val = ( struct . unpack ( '>L' , hs [ offset : ( offset + 4 ) ] ) [ 0 ] & 2147483647 ) #NEWLINE# return '{val:0{digits}d}' . format ( val = ( val % ( 10 ** digits ) ) , digits = digits )