#define _XOPEN_SOURCE
#define RAND_FILE "/dev/urandom"

#include <stdio.h>
#include <unistd.h>
#include <ctype.h>
#include <fcntl.h>

int main ( int argc, char *argv[] )
{
	int i = 0;
	int rand_file = 0;
	char c;
	char salt[26] = "$1$";

	if ( argc != 2 )
	{
		fprintf(stderr, "Next time can you insert a password to encrypt ?\n");
		return 1;
	}
	
	rand_file = open(RAND_FILE, O_RDONLY);
	
	i = 3;
	
	do
	{
		read(rand_file, &c, 1);
		
		if ( isalnum(c))
		{
			salt[i] = c;
			i++;
		}
	} while ( i < 25 );
	
	printf("Encrypted password is %s\n", crypt(argv[1], salt));
	return 0;
}
