-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrack.c
127 lines (114 loc) · 2.67 KB
/
crack.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include <cs50.h>
#include <stdio.h>
#include <crypt.h>
#include <string.h>
char intToChar(int i);
char AlphaCharGen(int value);
void PassGen();
string cropString(string s, int l);
int main(int argc, string argv[])
{
// Check inputs are valid
if (argc != 2)
{
printf("Usage: ./crack hash\n");
return 1;
}
else if (strlen(argv[1]) != 13)
{
printf("Usage: ./crack hash\n");
return 1;
}
// Main program
PassGen(argv[1]);
}
void PassGen(string hash)
{
// Preamble
char testString[6] = {' ', ' ', ' ', ' ', ' ', '\0'};
string salt;
char arr[3] = {' ', ' ', '\0'};
for (int i = 0; i < 2; i++)
{
arr[i] = hash[i];
}
salt = arr;
// Main loop
for (int i = 0; i < 53; i++)
{
for (int j = 0; j < 53; j++)
{
for (int k = 0; k < 53; k++)
{
for (int l = 0; l < 53; l++)
{
for (int m = 1; m < 53; m++)
{
testString[4] = AlphaCharGen(m);
// Meat of code goes here
string artiHash = crypt(cropString(testString, 5), salt);
if (strncmp(artiHash, hash, 13) == 0)
{
printf("%s\n", cropString(testString, 5));
return;
}
}
testString[3] = AlphaCharGen(l);
}
testString[2] = AlphaCharGen(k);
}
testString[1] = AlphaCharGen(j);
}
testString[0] = AlphaCharGen(i);
}
}
// Takes a range of 1-56, NOT 0
char AlphaCharGen(int value)
{
if (value == 0)
{
value = 32;
}
else if (value >= 1 && value <= 26)
{
value += 64;
}
else
{
value += 70;
}
char a = intToChar(value);
return a;
// Value is 0: char is null
// Value is 1-26: char is in bound 65-90 (caps)
// Value is 27-52: char is in bound 97-122 (lower-case)
// NB: point of macro design... loop around to 1, instead of 0, when value hits 53
}
char intToChar(int i)
{
return (char) i;
}
string cropString(string s, int l)
{
int count = l;
for (int i = 0; i < l; i++)
{
if (s[i] == ' ')
{
count--;
}
}
char charOut[count + 1];
charOut[count] = '\0';
int placeHolder = 0;
for (int i = 0; i < l; i++)
{
if (s[i] != ' ')
{
charOut[placeHolder] = s[i];
placeHolder++;
}
}
string out = charOut;
return out;
}