+static bool all_bit_flips_match(uint32_t state, odd_even_t odd_even)
+{
+ for (uint16_t i = 0; i < 256; i++) {
+ if (nonces[i].BitFlip[odd_even] && i != best_first_bytes[0]) {
+ uint8_t j = 0; // number of common bits
+ uint8_t common_bits = best_first_bytes[0] ^ i;
+ uint32_t mask = 0xfffffff0;
+ if (odd_even == ODD_STATE) {
+ while ((common_bits & 0x01) == 0 && j < 8) {
+ j++;
+ common_bits >>= 1;
+ if (j % 2 == 0) { // the odd bits
+ mask >>= 1;
+ }
+ }
+ } else {
+ while ((common_bits & 0x01) == 0 && j < 8) {
+ j++;
+ common_bits >>= 1;
+ if (j % 2 == 1) { // the even bits
+ mask >>= 1;
+ }
+ }
+ }
+ mask &= 0x000fffff;
+ //printf("bytes 0x%02x and 0x%02x: %d common bits, mask = 0x%08x, state = 0x%08x, sum_a8 = %d", best_first_bytes[0], best_first_bytes[i], j, mask, state, sum_a8);
+ bool found_match = false;
+ uint32_t *p = find_first_state(state, mask, &statelist_bitflip, 0);
+ if (p != NULL) {
+ while ((state & mask) == (*p & mask) && (*p != 0xffffffff)) {
+ if (remaining_bits_match(j, best_first_bytes[0], i, state, (state&0x00fffff0) | *p, odd_even)) {
+ found_match = true;
+ // if ((odd_even == ODD_STATE && state == test_state_odd)
+ // || (odd_even == EVEN_STATE && state == test_state_even)) {
+ // printf("all_other_first_bytes_match(): %s test state: remaining bits matched. Bytes = %02x, %02x, Common Bits=%d, mask=0x%08x, PartSum(a8)=%d\n",
+ // odd_even==ODD_STATE?"odd":"even", best_first_bytes[0], best_first_bytes[i], j, mask, part_sum_a8);
+ // }
+ break;
+ } else {
+ // if ((odd_even == ODD_STATE && state == test_state_odd)
+ // || (odd_even == EVEN_STATE && state == test_state_even)) {
+ // printf("all_other_first_bytes_match(): %s test state: remaining bits didn't match. Bytes = %02x, %02x, Common Bits=%d, mask=0x%08x, PartSum(a8)=%d\n",
+ // odd_even==ODD_STATE?"odd":"even", best_first_bytes[0], best_first_bytes[i], j, mask, part_sum_a8);
+ // }
+ }
+ p++;
+ }
+ } else {
+ // if ((odd_even == ODD_STATE && state == test_state_odd)
+ // || (odd_even == EVEN_STATE && state == test_state_even)) {
+ // printf("all_other_first_bytes_match(): %s test state: couldn't find a matching state. Bytes = %02x, %02x, Common Bits=%d, mask=0x%08x, PartSum(a8)=%d\n",
+ // odd_even==ODD_STATE?"odd":"even", best_first_bytes[0], best_first_bytes[i], j, mask, part_sum_a8);
+ // }
+ }
+ if (!found_match) {
+ // if ((odd_even == ODD_STATE && state == test_state_odd)
+ // || (odd_even == EVEN_STATE && state == test_state_even)) {
+ // printf("all_other_first_bytes_match(): %s test state: Eliminated. Bytes = %02x, %02x, Common Bits = %d\n", odd_even==ODD_STATE?"odd":"even", best_first_bytes[0], best_first_bytes[i], j);
+ // }
+ return false;
+ }
+ }
+
+ }
+
+ return true;
+}
+
+
+#define INVALID_BIT (1<<30)
+#define SET_INVALID(pstate) (*(pstate) |= INVALID_BIT)
+#define IS_INVALID(state) (state & INVALID_BIT)
+