1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
// src/measure.c --- utility to measure time to bruteforce
//
// Copyright (c) 2026 Martin Michalec <martin@michalec.dev>
//
// SPDX-License-Identifier: MIT
//
// Commentary:
//
// Code:
#include <stddef.h>
#include <time.h>
#include <math.h>
#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
|