crypt extended
authorMarkus Bröker <mbroeker@largo.dyndns.tv>
Thu, 16 Apr 2009 12:49:11 +0200
changeset 32 9b56360ec64e
parent 31 c95a6a7e305c
child 33 5e0a954f7c0b
crypt extended committer: Markus Bröker <mbroeker@largo.homelinux.org>
Makefile
crypt.c
--- a/Makefile
+++ b/Makefile
@@ -120,7 +120,7 @@
 
 crypt: crypt.o
 	@echo Linking $< ...
-	@$(CC) $(CFLAGS) -o $@ $<
+	@$(CC) $(CFLAGS) -o $@ $< -lcrypt
 
 tokenpasting: tokenpasting.o
 	@echo Linking $< ...
--- a/crypt.c
+++ b/crypt.c
@@ -5,33 +5,24 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-#include <string.h>
+#include <time.h>
+#include <crypt.h>
+
+#define GETRANDOM(max) ('a'+(int)((float)max*rand()/RAND_MAX+1.0))
 
 int main (int argc, char **argv)
 {
-    char *data;
-
-    int i;
+    char salt[20] = { 0 };
 
     if (argc != 2) {
-        printf ("Usage: %s <str>\n", argv[0]);
-        return EXIT_SUCCESS;
+        printf ("Usage: %s <plaintext>\n", argv[0]);
+        return EXIT_FAILURE;
     }
 
-    /*
-     * Its already allocated
-     */
-    data = argv[1];
-
-    for (i = 0; data[i]; i++)
-        data[i] = data[i] + 1;
+    srand (time (NULL));
 
-    printf ("EnCrypted Data: %s\n", data);
+    sprintf (salt, "$1$%c%c", GETRANDOM (26), GETRANDOM (26));
 
-    for (i = 0; data[i]; i++)
-        data[i] = data[i] - 1;
-
-    printf ("DeCrypted Data: %s\n", data);
-
+    printf ("%s\n", crypt (argv[1], salt));
     return EXIT_SUCCESS;
 }