aboutsummaryrefslogtreecommitdiff
path: root/02/src/measure.c
diff options
context:
space:
mode:
authorLibravatar Martin Michalec <martin@michalec.dev>2026-11-11 05:31:06 +0000
committerLibravatar Martin Michalec <martin@michalec.dev>2026-11-11 06:14:42 +0000
commit9e1d304cac5367c3dbb1ca14700736680bd3a804 (patch)
tree31f328747acb934d365d423adfda144818ff5ad4 /02/src/measure.c
downloadlab-01-05-9e1d304cac5367c3dbb1ca14700736680bd3a804.tar.gz
publishHEADmaster
Diffstat (limited to '02/src/measure.c')
-rw-r--r--02/src/measure.c70
1 files changed, 70 insertions, 0 deletions
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 @@
1// src/measure.c --- utility to measure time to bruteforce
2//
3// Copyright (c) 2026 Martin Michalec <martin@michalec.dev>
4//
5// SPDX-License-Identifier: MIT
6//
7// Commentary:
8//
9// Code:
10
11#include <stddef.h>
12#include <time.h>
13#include <math.h>
14
15#include "cracking.h"
16
17int
18main (int argc, char *argv[])
19{
20 if (argc != 2) {
21 fprintf (stderr, "Usage: %s LOGIN\n", argv[0]);
22 fprintf (stderr, "Note: LOGIN shouldn't have password of length 3 or 4\n");
23 exit (EXIT_FAILURE);
24 }
25
26 struct shell shell = spawn_shell ();
27 clock_t start, end;
28
29 struct string_view login = SVCSTR (argv[1]);
30 struct string_builder password = {0};
31 STRING_BUILDER_APPEND_STRING_VIEW (password, SVCSTR ("A!!"));
32
33 start = clock();
34 while (password.length == 3) {
35 test_credentials (shell, login, SVSB (password));
36 password_bump (&password);
37 } end = clock();
38 double time3 = (end - start) /(double) CLOCKS_PER_SEC;
39
40 double per_try3 = time3/(52*72*72);
41 double time4_expected = per_try3*(52*pow (72, 3));
42 printf ("Tried all 3 letter passwords in: %fs\n", time3);
43 printf ("Expected time to try all 4 letter passwords: %f min\n", time4_expected/60);
44
45 start = clock();
46 while (password.length == 4) {
47 test_credentials (shell, login, SVSB (password));
48 password_bump (&password);
49 } end = clock();
50 double time4 = (end - start) /(double) CLOCKS_PER_SEC;
51
52 double per_try4 = time4/(52*72*72*72);
53 double per_try = (per_try3 + per_try4)/2;
54
55 double time5 = per_try*(52*pow (72, 4));
56 double time6 = per_try*(52*pow (72, 5));
57 double time7 = per_try*(52*pow (72, 6));
58 double time8 = per_try*(52*pow (72, 7));
59
60 printf ("Real time to try 3 letter passwords: %fs\n", time3);
61 printf ("Real time to try 4 letter passwords: %fs\n", time4);
62 printf ("Estimated time to try 5 letter passwords: %fs\n", time5);
63 printf ("Estimated time to try 6 letter passwords: %fs\n", time6);
64 printf ("Estimated time to try 7 letter passwords: %fs\n", time7);
65 printf ("Estimated time to try 8 letter passwords: %fs\n", time8);
66
67 return EXIT_SUCCESS;
68}
69
70// src/measure.c ends here