-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathpwhash.c
executable file
·157 lines (126 loc) · 3.07 KB
/
pwhash.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#define _GNU_SOURCE
#include <ctype.h>
#include <dirent.h>
#include <fcntl.h>
#include <ftw.h>
#include <libgen.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <time.h>
#include <unistd.h>
#include <utime.h>
#include <openssl/sha.h>
#include <openssl/md5.h>
#include <openssl/md4.h>
/*===========================================================================*/
int main(int argc, char *argv[])
{
int p;
int k;
int maclen = 12;
int keysetlen = 58;
char *macstring = NULL;
char *keystring = NULL;
SHA_CTX ctxsha1;
SHA256_CTX ctxsha256;
SHA512_CTX ctxsha512;
MD5_CTX ctxmd5;
MD4_CTX ctxmd4;
unsigned char digestsha1[SHA_DIGEST_LENGTH];
unsigned char digestsha256[SHA256_DIGEST_LENGTH];
unsigned char digestsha512[SHA512_DIGEST_LENGTH];
unsigned char digestmd5[MD5_DIGEST_LENGTH];
unsigned char digestmd4[MD4_DIGEST_LENGTH];
char testmacstring[] = "112233445566";
char testkeysetstring[] = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
macstring = testmacstring;
keystring = testkeysetstring;
if(argc == 3)
{
macstring = argv[1];
maclen = strlen(argv[1]);
keystring = argv[2];
keysetlen = strlen(argv[2]);
}
else
{
printf("usage: pwhash word charset\nexample: pwhash %s %s\n", testmacstring, testkeysetstring);
}
SHA512_Init(&ctxsha512);
SHA512_Update(&ctxsha512, macstring, maclen);
SHA512_Final(digestsha512, &ctxsha512);
printf("\nsha512-hex...: ");
for (p = 0; p < SHA512_DIGEST_LENGTH; p++)
{
printf("%02x",digestsha512[p]);
}
printf("\nsha512-ascii.: ");
for (p = 0; p < SHA512_DIGEST_LENGTH; p++)
{
k = (digestsha512[p] %keysetlen);
printf("%c",keystring[k]);
}
SHA256_Init(&ctxsha256);
SHA256_Update(&ctxsha256, macstring, maclen);
SHA256_Final(digestsha256, &ctxsha256);
printf("\nsha256-hex...: ");
for (p = 0; p < SHA256_DIGEST_LENGTH; p++)
{
printf("%02x",digestsha256[p]);
}
printf("\nsha256-ascii.: ");
for (p = 0; p < SHA256_DIGEST_LENGTH; p++)
{
k = (digestsha256[p] %keysetlen);
printf("%c",keystring[k]);
}
SHA1_Init(&ctxsha1);
SHA1_Update(&ctxsha1, macstring, maclen);
SHA1_Final(digestsha1, &ctxsha1);
printf("\nsha1-hex.....: ");
for (p = 0; p < SHA_DIGEST_LENGTH; p++)
{
printf("%02x",digestsha1[p]);
}
printf("\nsha1-ascii...: ");
for (p = 0; p < SHA_DIGEST_LENGTH; p++)
{
k = (digestsha1[p] %keysetlen);
printf("%c",keystring[k]);
}
MD5_Init(&ctxmd5);
MD5_Update(&ctxmd5, macstring, maclen);
MD5_Final(digestmd5, &ctxmd5);
printf("\nmd5-hex......: ");
for (p = 0; p < MD5_DIGEST_LENGTH; p++)
{
printf("%02x",digestmd5[p]);
}
printf("\nmd5-ascii....: ");
for (p = 0; p < MD5_DIGEST_LENGTH; p++)
{
k = (digestmd5[p] %keysetlen);
printf("%c",keystring[k]);
}
MD4_Init(&ctxmd4);
MD4_Update(&ctxmd4, macstring, maclen);
MD4_Final(digestmd4, &ctxmd4);
printf("\nmd4-hex......: ");
for (p = 0; p < MD4_DIGEST_LENGTH; p++)
{
printf("%02x",digestmd4[p]);
}
printf("\nmd4-ascii....: ");
for (p = 0; p < MD4_DIGEST_LENGTH; p++)
{
k = (digestmd4[p] %keysetlen);
printf("%c",keystring[k]);
}
printf("\n");
return EXIT_SUCCESS;
}