- //Create the intersection:
- if (par_info == 0 )
- if ( last_keylist != NULL)
- {
- int64_t *p1, *p2, *p3;
- p1 = p3 = last_keylist;
- p2 = state_s;
- while ( *p1 != -1 && *p2 != -1 ) {
- if (compar_state(p1, p2) == 0) {
- printf("p1:%d p2:%d p3:%d key:%012llx\n",p1-last_keylist, p2-state_s, p3-last_keylist,*p1);
- *p3++ = *p1++;
- p2++;
- }
- else {
- while (compar_state(p1, p2) == -1) ++p1;
- while (compar_state(p1, p2) == 1) ++p2;
- }
- }
- key_count = p3 - last_keylist;;
+ uid = myuid;//(uint32_t)bytes_to_num(data + 0, 4);
+ nt = *(uint32_t*)(data+8);
+ nr0_enc = *(uint32_t*)(data+12);
+ ar0_enc = *(uint32_t*)(data+16);
+ nr1_enc = *(uint32_t*)(data+32);
+ ar1_enc = *(uint32_t*)(data+36);
+
+ // PrintAndLog("recovering key for:");
+ // PrintAndLog(" uid: %08x %08x",uid, myuid);
+ // PrintAndLog(" nt: %08x",nt);
+ // PrintAndLog(" {nr_0}: %08x",nr0_enc);
+ // PrintAndLog(" {ar_0}: %08x",ar0_enc);
+ // PrintAndLog(" {nr_1}: %08x",nr1_enc);
+ // PrintAndLog(" {ar_1}: %08x",ar1_enc);
+
+ s = lfsr_recovery32(ar0_enc ^ prng_successor(nt, 64), 0);
+
+ for(t = s; t->odd | t->even; ++t) {
+ lfsr_rollback_word(t, 0, 0);
+ lfsr_rollback_word(t, nr0_enc, 1);
+ lfsr_rollback_word(t, uid ^ nt, 0);
+ crypto1_get_lfsr(t, &key);
+ crypto1_word(t, uid ^ nt, 0);
+ crypto1_word(t, nr1_enc, 1);
+ if (ar1_enc == (crypto1_word(t, 0, 0) ^ prng_successor(nt, 64))) {
+ PrintAndLog("Found Key: [%012"llx"]", key);
+ isSuccess = TRUE;
+ ++counter;
+ if (counter==20)
+ break;