code: def generate_hotp(secret, counter=4):
      
      # https://tools.ietf.org/html/rfc4226
      msg = struct.pack('>Q', counter)
      digest = hmac.new(to_bytes(secret), msg, hashlib.sha1).digest()
  
      ob = digest[19]
      if PY2:
          ob = ord(ob)
  
      pos = ob & 15
      base = struct.unpack('>I', digest[pos:pos + 4])[0] & 0x7fffffff
      token = base % 1000000
      return token
docs: Generate a HOTP code.
  
      :param secret: A secret token for the authentication.
      :param counter: HOTP is a counter based algorithm.