-
Notifications
You must be signed in to change notification settings - Fork 0
/
101-keygen.c
60 lines (51 loc) · 939 Bytes
/
101-keygen.c
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
/*
* File: 101-keygen.c
*
* Author: Stanley O. Ajanaku
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
/**
* main - Generates a random valid password for
* the program 101-crackme.
*
* Return: Always 0.
*/
int main(void)
{
char password[84];
int index = 0, sum = 0, diff_half1, diff_half2;
srand(time(0));
while (sum < 2772)
{
password[index] = 33 + rand() % 94;
sum += password[index++];
}
password[index] = '\0';
if (sum != 2772)
{
diff_half1 = (sum - 2772) / 2;
diff_half2 = (sum - 2772) / 2;
if ((sum - 2772) % 2 != 0)
diff_half1++;
for (index = 0; password[index]; index++)
{
if (password[index] >= (33 + diff_half1))
{
password[index] -= diff_half1;
break;
}
}
for (index = 0; password[index]; index++)
{
if (password[index] >= (33 + diff_half2))
{
password[index] -= diff_half2;
break;
}
}
}
printf("%s", password);
return (0);
}