author | Markus Bröker <mbroeker@largo.dyndns.tv> |
Fri, 19 Nov 2010 16:43:20 +0100 | |
changeset 161 | 36f763c8ab16 |
parent 131 | b5ad49852adc |
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 |
||
131
b5ad49852adc
check for the return values
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
128
diff
changeset
|
6 |
#define _XOPEN_SOURCE 500 |
b5ad49852adc
check for the return values
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
128
diff
changeset
|
7 |
|
0 | 8 |
#include <stdio.h> |
9 |
#include <stdlib.h> |
|
32 | 10 |
#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
|
11 |
#include <unistd.h> |
305d2ca32936
crypt.h seems to be broken on many systems.
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
12 |
|
74
829976007e62
getrandom macro fixed
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
56
diff
changeset
|
13 |
#define GETRANDOM(max) ('a'+(int)((float)(max)*rand()/RAND_MAX+1.0)) |
0 | 14 |
|
15 |
int main (int argc, char **argv) |
|
16 |
{ |
|
56 | 17 |
char salt[12] = { 0 }; |
0 | 18 |
|
19 |
if (argc != 2) { |
|
32 | 20 |
printf ("Usage: %s <plaintext>\n", argv[0]); |
21 |
return EXIT_FAILURE; |
|
0 | 22 |
} |
23 |
||
32 | 24 |
srand (time (NULL)); |
0 | 25 |
|
56 | 26 |
sprintf (salt, "$1$%c%c%c%c%c%c%c%c", |
27 |
GETRANDOM (26), GETRANDOM (26), |
|
28 |
GETRANDOM (26), GETRANDOM (26), GETRANDOM (26), GETRANDOM (26), GETRANDOM (26), GETRANDOM (26)); |
|
0 | 29 |
|
32 | 30 |
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
|
31 |
return EXIT_SUCCESS; |
0 | 32 |
} |