--- 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;
}