crypt.c
author Markus Bröker <mbroeker@largo.dyndns.tv>
Thu, 16 Apr 2009 12:49:12 +0200
changeset 53 6b3d7e3418c1
parent 32 9b56360ec64e
child 56 966ad681f25d
permissions -rw-r--r--
getch.c renamed to cross_getch.c committer: Markus Bröker <mbroeker@largo.homelinux.org>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
af501b0c1716 demos cvs copy
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     1
/**
9
c3fecc82ade6 standard tags for git projects
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 8
diff changeset
     2
 * test/demos/crypt.c
c3fecc82ade6 standard tags for git projects
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 8
diff changeset
     3
 * Copyright (C) 2008 Markus Broeker
0
af501b0c1716 demos cvs copy
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     4
 */
af501b0c1716 demos cvs copy
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     5
af501b0c1716 demos cvs copy
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     6
#include <stdio.h>
af501b0c1716 demos cvs copy
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     7
#include <stdlib.h>
32
9b56360ec64e crypt extended
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 27
diff changeset
     8
#include <time.h>
9b56360ec64e crypt extended
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 27
diff changeset
     9
#include <crypt.h>
9b56360ec64e crypt extended
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 27
diff changeset
    10
9b56360ec64e crypt extended
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 27
diff changeset
    11
#define GETRANDOM(max) ('a'+(int)((float)max*rand()/RAND_MAX+1.0))
0
af501b0c1716 demos cvs copy
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    12
af501b0c1716 demos cvs copy
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    13
int main (int argc, char **argv)
af501b0c1716 demos cvs copy
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    14
{
32
9b56360ec64e crypt extended
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 27
diff changeset
    15
    char salt[20] = { 0 };
0
af501b0c1716 demos cvs copy
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    16
af501b0c1716 demos cvs copy
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    17
    if (argc != 2) {
32
9b56360ec64e crypt extended
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 27
diff changeset
    18
        printf ("Usage: %s <plaintext>\n", argv[0]);
9b56360ec64e crypt extended
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 27
diff changeset
    19
        return EXIT_FAILURE;
0
af501b0c1716 demos cvs copy
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    20
    }
af501b0c1716 demos cvs copy
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    21
32
9b56360ec64e crypt extended
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 27
diff changeset
    22
    srand (time (NULL));
0
af501b0c1716 demos cvs copy
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    23
32
9b56360ec64e crypt extended
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 27
diff changeset
    24
    sprintf (salt, "$1$%c%c", GETRANDOM (26), GETRANDOM (26));
0
af501b0c1716 demos cvs copy
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    25
32
9b56360ec64e crypt extended
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 27
diff changeset
    26
    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
    27
    return EXIT_SUCCESS;
0
af501b0c1716 demos cvs copy
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    28
}