Пример #1
0
def auth_card(mf_reader: MFRC522, uid, key_bin, block, key_a, format):
    cmd = mf_reader.PICC_AUTHENT1A if key_a else mf_reader.PICC_AUTHENT1B
    if key_bin is not None:
        trailer_block = get_trailer_block(block)
        if key_a:
            key = key_bin[trailer_block * 16:(trailer_block * 16) + 6]
        else:
            key = key_bin[(trailer_block * 16) + 10:(trailer_block * 16) + 16]
        if mf_reader.MFRC522_Auth(cmd, block, key, uid) == mf_reader.MI_OK:
            return True, key
    if format or key_bin is None:
        for key in GUESS_KEYS:
            if mf_reader.MFRC522_Auth(cmd, block, key, uid) == mf_reader.MI_OK:
                return True, key
            # Try to anticol again.
            mf_reader.MFRC522_HaltA()
            mf_reader.antennaOff()
            time.sleep(0.1)
            mf_reader.antennaOn()
            (success, _) = anticol(mf_reader,
                                   print_info=False,
                                   wakeup=True,
                                   no_rats=True)
            if not success:
                print('tag was removed', end='')
                return False, None
    # Faild to find keys.
    return False, None
Пример #2
0
def re_anticol(mf_reader: MFRC522):
    # Try to anticol again.
    mf_reader.MFRC522_HaltA()
    mf_reader.antennaOff()
    mf_reader.antennaOn()
    (success, _) = anticol(mf_reader,
                           print_info=False,
                           wakeup=True,
                           no_rats=True)
    if not success:
        print('Tag has been removed')
        exit(-1)