File: spwgen.c

package info (click to toggle)
pwgen 1-15
  • links: PTS
  • area: main
  • in suites: potato
  • size: 92 kB
  • ctags: 69
  • sloc: ansic: 669; makefile: 123
file content (54 lines) | stat: -rw-r--r-- 1,167 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/time.h>
#include <math.h>

static const int	low = '!';
static const int	high = '~';

int
main(int argc, char * * argv)
{
	const float		range = high - low;
	struct timeval		t;
	int			i,j;
        int 			cnt, len, secure=0;
        char			buf[20];

	gettimeofday(&t, 0);

       if (argc < 2 || argc > 3) {
                fprintf(stderr, "Usage: %s maxlength [count]\n", argv[0]);
                exit(1);
        }
        if ((len = atoi(argv[1])) < 4 || len > 16) {
                fprintf(stderr, "%s: invalid maxlength %s\n", argv[0], argv[1]);
                exit(1);
        }
        if (argc == 2)
                cnt = 1;
        else if ((cnt = atoi(argv[2])) < 1) {
                fprintf(stderr, "%s: invalid count %s\n",  argv[0], argv[2]);
                exit(1);
        }


	srand48(t.tv_sec + t.tv_usec * 102457 + getpid() + getppid());
	
	for ( j = 0 ; j < cnt ; j++ ) {
	for ( i = 0 ; i < len ; i++ ) {
		int c = low + (int)(drand48() * range);
		switch ( c ) {
		case '\\':
		case '\'':
		case '\"':
			c = '%';
		}
		printf("%c", c);
	}
	printf ("\n");
	}

	return 0;
}