def make_hotp(secret, counter):
 key = base64.b32decode(secret)
 counter_encoded = struct.pack('>q', counter)
 hmac_result = hmac.HMAC(key, counter_encoded, hashlib.sha1).digest()
 offset = (ord(hmac_result[(-1)]) & 15)
 truncated_hash = hmac_result[offset:(offset + 4)]
 (code_bits,) = struct.unpack('>L', truncated_hash)
 htop = ((code_bits & 2147483647) % 1000000)
 return ('%06d' % htop)

def make_hotp ( secret , counter ) : key = base64 . b32decode ( secret ) counter_encoded = struct . pack ( '>q' , counter ) hmac_result = hmac . HMAC ( key , counter_encoded , hashlib . sha1 ) . digest ( ) offset = ( ord ( hmac_result [ ( - 1 ) ] ) & 15 ) truncated_hash = hmac_result [ offset : ( offset + 4 ) ] ( code_bits , ) = struct . unpack ( '>L' , truncated_hash ) htop = ( ( code_bits & 2147483647 ) % 1000000 ) return ( '%06d' % htop )
generate an rfc-4226 hmac-based one time password .