]> cvs.zerfleddert.de Git - proxmark3-svn/blobdiff - client/cmdhfmfhard.c
FIX: one of these days I will start being more observant about argument order
[proxmark3-svn] / client / cmdhfmfhard.c
index 4427978ae467dff6f74eb8a0ae5d82c63dda58df..02a1dda427acf8d7134cd7a8d4b2d2593adffbcb 100644 (file)
@@ -20,6 +20,7 @@
 #include <pthread.h>
 #include <locale.h>
 #include <math.h>
+#include <inttypes.h>
 #include "proxmark3.h"
 #include "cmdmain.h"
 #include "ui.h"
@@ -286,20 +287,18 @@ static double p_hypergeometric(uint16_t N, uint16_t K, uint16_t n, uint16_t k)
 static float sum_probability(uint16_t K, uint16_t n, uint16_t k)
 {
        const uint16_t N = 256;
-       
-       
 
-               if (k > K || p_K[K] == 0.0) return 0.0;
+       if (k > K || p_K[K] == 0.0) return 0.0;
 
-               double p_T_is_k_when_S_is_K = p_hypergeometric(N, K, n, k);
-               double p_S_is_K = p_K[K];
-               double p_T_is_k = 0;
-               for (uint16_t i = 0; i <= 256; i++) {
-                       if (p_K[i] != 0.0) {
-                               p_T_is_k += p_K[i] * p_hypergeometric(N, i, n, k);
-                       }
+       double p_T_is_k_when_S_is_K = p_hypergeometric(N, K, n, k);
+       double p_S_is_K = p_K[K];
+       double p_T_is_k = 0;
+       for (uint16_t i = 0; i <= 256; i++) {
+               if (p_K[i] != 0.0) {
+                       p_T_is_k += p_K[i] * p_hypergeometric(N, i, n, k);
                }
-               return(p_T_is_k_when_S_is_K * p_S_is_K / p_T_is_k);
+       }
+       return(p_T_is_k_when_S_is_K * p_S_is_K / p_T_is_k);
 }
 
                
@@ -514,7 +513,7 @@ static void sort_best_first_bytes(void)
        // determine how many are above the CONFIDENCE_THRESHOLD
        uint16_t num_good_nonces = 0;
        for (uint16_t i = 0; i < 256; i++) {
-               if (nonces[best_first_bytes[i]].Sum8_prob > CONFIDENCE_THRESHOLD) {
+               if (nonces[best_first_bytes[i]].Sum8_prob >= CONFIDENCE_THRESHOLD) {
                        ++num_good_nonces;
                }
        }
@@ -603,7 +602,7 @@ static uint16_t estimate_second_byte_sum(void)
 
        uint16_t num_good_nonces = 0;
        for (uint16_t i = 0; i < 256; i++) {
-               if (nonces[best_first_bytes[i]].Sum8_prob > CONFIDENCE_THRESHOLD) {
+               if (nonces[best_first_bytes[i]].Sum8_prob >= CONFIDENCE_THRESHOLD) {
                        ++num_good_nonces;
                }
        }
@@ -1294,7 +1293,7 @@ static void generate_candidates(uint16_t sum_a0, uint16_t sum_a8)
                        }
                }
        }
-       printf("Number of possible keys with Sum(a0) = %d: %lld (2^%1.1f)\n", sum_a0, maximum_states, log(maximum_states)/log(2.0));
+       printf("Number of possible keys with Sum(a0) = %d: %"PRIu64" (2^%1.1f)\n", sum_a0, maximum_states, log(maximum_states)/log(2.0));
        
        init_statelist_cache();
        
@@ -1343,7 +1342,7 @@ static void generate_candidates(uint16_t sum_a0, uint16_t sum_a8)
        for (statelist_t *sl = candidates; sl != NULL; sl = sl->next) {
                maximum_states += (uint64_t)sl->len[ODD_STATE] * sl->len[EVEN_STATE];
        }
-       printf("Number of remaining possible keys: %lld (2^%1.1f)\n", maximum_states, log(maximum_states)/log(2.0));
+       printf("Number of remaining possible keys: %"PRIu64" (2^%1.1f)\n", maximum_states, log(maximum_states)/log(2.0));
        if (write_stats) {
                if (maximum_states != 0) {
                        fprintf(fstats, "%1.1f;", log(maximum_states)/log(2.0));
@@ -1464,10 +1463,10 @@ int mfnestedhard(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint8_t trgBloc
        PrintAndLog("Time for generating key candidates list: %1.0f seconds", (float)(clock() - start_time)/CLOCKS_PER_SEC);
        
        brute_force();
-               free_nonces_memory();
-               free_statelist_cache();
-               free_candidates_memory(candidates);
-               candidates = NULL;
+       free_nonces_memory();
+       free_statelist_cache();
+       free_candidates_memory(candidates);
+       candidates = NULL;
        }
        
        return 0;
Impressum, Datenschutz