author | Markus Bröker <mbroeker@largo.dyndns.tv> |
Fri, 05 Mar 2010 23:16:32 +0100 | |
changeset 119 | 305d2ca32936 |
parent 77 | 49e0babccb23 |
child 128 | efa226a4801e |
permissions | -rw-r--r-- |
0 | 1 |
/** |
77 | 2 |
* crypt.c |
9
c3fecc82ade6
standard tags for git projects
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
8
diff
changeset
|
3 |
* Copyright (C) 2008 Markus Broeker |
0 | 4 |
*/ |
5 |
||
6 |
#include <stdio.h> |
|
7 |
#include <stdlib.h> |
|
32 | 8 |
#include <time.h> |
119
305d2ca32936
crypt.h seems to be broken on many systems.
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
9 |
#include <unistd.h> |
305d2ca32936
crypt.h seems to be broken on many systems.
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
10 |
|
305d2ca32936
crypt.h seems to be broken on many systems.
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
11 |
#ifndef NO_CRYPT |
32 | 12 |
#include <crypt.h> |
119
305d2ca32936
crypt.h seems to be broken on many systems.
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
13 |
#endif |
32 | 14 |
|
74
829976007e62
getrandom macro fixed
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
56
diff
changeset
|
15 |
#define GETRANDOM(max) ('a'+(int)((float)(max)*rand()/RAND_MAX+1.0)) |
0 | 16 |
|
17 |
int main (int argc, char **argv) |
|
18 |
{ |
|
56 | 19 |
char salt[12] = { 0 }; |
0 | 20 |
|
21 |
if (argc != 2) { |
|
32 | 22 |
printf ("Usage: %s <plaintext>\n", argv[0]); |
23 |
return EXIT_FAILURE; |
|
0 | 24 |
} |
25 |
||
32 | 26 |
srand (time (NULL)); |
0 | 27 |
|
56 | 28 |
sprintf (salt, "$1$%c%c%c%c%c%c%c%c", |
29 |
GETRANDOM (26), GETRANDOM (26), |
|
30 |
GETRANDOM (26), GETRANDOM (26), GETRANDOM (26), GETRANDOM (26), GETRANDOM (26), GETRANDOM (26)); |
|
0 | 31 |
|
32 | 32 |
printf ("%s\n", crypt (argv[1], salt)); |
8
96d16dfe787a
We use return EXIT_SUCCESS instead of return 0
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
33 |
return EXIT_SUCCESS; |
0 | 34 |
} |