From 9e1d304cac5367c3dbb1ca14700736680bd3a804 Mon Sep 17 00:00:00 2001 From: Martin Michalec Date: Wed, 11 Nov 2026 08:31:06 +0300 Subject: publish --- 02/src/measure.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 02/src/measure.c (limited to '02/src/measure.c') diff --git a/02/src/measure.c b/02/src/measure.c new file mode 100644 index 0000000..72633bc --- /dev/null +++ b/02/src/measure.c @@ -0,0 +1,70 @@ +// src/measure.c --- utility to measure time to bruteforce +// +// Copyright (c) 2026 Martin Michalec +// +// SPDX-License-Identifier: MIT +// +// Commentary: +// +// Code: + +#include +#include +#include + +#include "cracking.h" + +int +main (int argc, char *argv[]) +{ + if (argc != 2) { + fprintf (stderr, "Usage: %s LOGIN\n", argv[0]); + fprintf (stderr, "Note: LOGIN shouldn't have password of length 3 or 4\n"); + exit (EXIT_FAILURE); + } + + struct shell shell = spawn_shell (); + clock_t start, end; + + struct string_view login = SVCSTR (argv[1]); + struct string_builder password = {0}; + STRING_BUILDER_APPEND_STRING_VIEW (password, SVCSTR ("A!!")); + + start = clock(); + while (password.length == 3) { + test_credentials (shell, login, SVSB (password)); + password_bump (&password); + } end = clock(); + double time3 = (end - start) /(double) CLOCKS_PER_SEC; + + double per_try3 = time3/(52*72*72); + double time4_expected = per_try3*(52*pow (72, 3)); + printf ("Tried all 3 letter passwords in: %fs\n", time3); + printf ("Expected time to try all 4 letter passwords: %f min\n", time4_expected/60); + + start = clock(); + while (password.length == 4) { + test_credentials (shell, login, SVSB (password)); + password_bump (&password); + } end = clock(); + double time4 = (end - start) /(double) CLOCKS_PER_SEC; + + double per_try4 = time4/(52*72*72*72); + double per_try = (per_try3 + per_try4)/2; + + double time5 = per_try*(52*pow (72, 4)); + double time6 = per_try*(52*pow (72, 5)); + double time7 = per_try*(52*pow (72, 6)); + double time8 = per_try*(52*pow (72, 7)); + + printf ("Real time to try 3 letter passwords: %fs\n", time3); + printf ("Real time to try 4 letter passwords: %fs\n", time4); + printf ("Estimated time to try 5 letter passwords: %fs\n", time5); + printf ("Estimated time to try 6 letter passwords: %fs\n", time6); + printf ("Estimated time to try 7 letter passwords: %fs\n", time7); + printf ("Estimated time to try 8 letter passwords: %fs\n", time8); + + return EXIT_SUCCESS; +} + +// src/measure.c ends here -- cgit v1.3.1