diff options
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | sand-leek.c | 88 |
2 files changed, 86 insertions, 4 deletions
@@ -1,5 +1,5 @@ CFLAGS += -Wall -Wextra -O2 -LDFLAGS += -lssl -lcrypto -lpthread +LDFLAGS += -lssl -lcrypto -lpthread -lm all: sand-leek diff --git a/sand-leek.c b/sand-leek.c index e4f73a0..d18b806 100644 --- a/sand-leek.c +++ b/sand-leek.c @@ -6,6 +6,7 @@ #include <semaphore.h> #include <errno.h> #include <string.h> +#include <math.h> #include <openssl/rsa.h> #include <openssl/sha.h> #include <openssl/pem.h> @@ -230,12 +231,38 @@ die_usage(const char *argv0) { exit(1); } +void nice_time(long sec, int *seconds, int *minutes, int *hours, int *days) { + *seconds = sec % 60; sec -= *seconds; sec /= 60; + *minutes = sec % 60; sec -= *minutes; sec /= 60; + *hours = sec % 24; sec -= *hours ; sec /= 24; + *days = sec % 24; +} + void monitor_progress(unsigned long volatile *khashes, int thread_count) { int loops = 0; int i = 0; unsigned long total_khashes = 0; unsigned long last_total_khashes = 0; + double hashes_nice = 0; + char *hashes_nice_unit = NULL; + struct timespec start = {}; + struct timespec now = {}; + int seconds = 0; + int minutes = 0; + int hours = 0; + int days = 0; + long delta = 0; + long est_khashes = 0; + long remaining = 0; + long remaining_abs = 0; + char *remaining_unit = NULL; + + /* estimated khashes required for approximate certainty of finding a key */ + est_khashes = pow(32, search_len) / 1000; + + /* FIXME linux-only? Need a portable alternative or (shriek) ifdefs */ + clock_gettime(CLOCK_MONOTONIC, &start); loops = 0; /* loop while no thread as announced work end; we don't want to @@ -247,11 +274,66 @@ monitor_progress(unsigned long volatile *khashes, int thread_count) { for (i = 0; i < thread_count; i++) { total_khashes += khashes[i]; } - iprintf("Last second: %lu kH/s (%.2f kH/s/thread) | Average: %.2f kH/s (%.2f kH/s/thread)\r", + + /* compute approximate total hashes for this run and format it + * nicely with a unit and everything */ + /* FIXME factor out and apply this to the current hashrate display */ + if (total_khashes > 1e15) { + hashes_nice = total_khashes / 1e15; + hashes_nice_unit = "E"; + } else if (total_khashes > 1e12) { + hashes_nice = total_khashes / 1e12; + hashes_nice_unit = "P"; + } else if (total_khashes > 1e9) { + hashes_nice = total_khashes / 1e9; + hashes_nice_unit = "T"; + } else if (total_khashes > 1e6) { + hashes_nice = total_khashes / 1e6; + hashes_nice_unit = "G"; + } else if (total_khashes > 1e3) { + hashes_nice = total_khashes / 1e3; + hashes_nice_unit = "M"; + } else { + hashes_nice = total_khashes; + hashes_nice_unit = "k"; + } + + /* compute timestamp */ + clock_gettime(CLOCK_MONOTONIC, &now); + delta = now.tv_sec - start.tv_sec; + nice_time(delta, &seconds, &minutes, &hours, &days); + + if (total_khashes - last_total_khashes == 0) { + remaining = 0; + } else { + remaining = (est_khashes/(total_khashes-last_total_khashes)) - delta; + } + + /* FIXME factor out */ + remaining_abs = labs(remaining); + if (remaining_abs < 60) { + remaining_unit = "second"; + } else if (remaining_abs < 60*60) { + remaining = (remaining + 30) / 60; + remaining_unit = "minute"; + } else if (remaining_abs < 60*60*24) { + remaining = (remaining + 1800) / 3600; + remaining_unit = "hour"; + } else if (remaining_abs < 60*60*24*365.25) { + remaining = (remaining + 43200) / 86400; + remaining_unit = "day"; + } else { + remaining = (remaining + (60*60*24*365.25)/2) / (60*60*24*365.25); + remaining_unit = "year"; + } + + iprintf("[%02d:%02d:%02d:%02d]: %.2f %s hashes%s. Now ~%lu kH/s (%.2f kH/s/thread). Maybe %ld %s%s left \r", + days, hours, minutes, seconds, + hashes_nice, hashes_nice_unit, (hashes_nice > 1000 ? " (!!)" : ""), total_khashes - last_total_khashes, (double)(total_khashes - last_total_khashes) / thread_count, - (double)total_khashes / (loops ? loops : 1), - ((double)total_khashes / (loops ? loops : 1)) / thread_count); + remaining, remaining_unit, (remaining == 1 ? "" : "s" ) + ); sleep(1); loops++; } |