<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def validate_otp(hsm, args):
 """ Validate an OTP. """

    try:
        res = pyhsm.yubikey.validate_otp(hsm, args.otp)
        if args.verbose:
            print "OK counter=%04x low=%04x high=%02x use=%02x" % \
                (res.use_ctr, res.ts_low, res.ts_high, res.session_ctr)
        return 0
    except pyhsm.exception.YHSM_CommandFailed, e:
        if args.verbose:
            print "%s" % (pyhsm.defines.status2str(e.status))
        # figure out numerical response code
        for r in [pyhsm.defines.YSM_OTP_INVALID, \
                      pyhsm.defines.YSM_OTP_REPLAY, \
                      pyhsm.defines.YSM_ID_NOT_FOUND]:
            if e.status == r:
                return r - pyhsm.defines.YSM_RESPONSE
        # not found
        return 0xff