For kicks I wrote up a Password generator after lunch. Let me start with the code:
unsigned int x,y,z,c;
unsigned int KISS();
unsigned int devrand();
int main( int argc, char** argv )
{
int i, j = 1;
char pwd[] = "abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"1234567890"
"!@#$";
char password[12];
if( argv[1] )
j = atoi(argv[1]);
do {
memset( password, '\0', sizeof(password) );
for( i = 0; i < sizeof(password); ++i )
password = (char)pwd[(KISS() % strlen( pwd ))];
printf("%s\n", password);
--j;
} while( j );
return 0;
}
/*
* Fairly popular Random Number generator
*/
unsigned int KISS()
{
x = devrand();
while(!(y=devrand())); // y must not be zero
z = devrand();
c = devrand();
unsigned long long t;
unsigned long long a = 698769069ULL;
x = 69069*x + 12345;
y ^= (y<<13);
y ^= (y>>17);
y ^= (y<<5);
t = a*z+c;
c = (t>>32);
return x+y+(z=t);
}
/*
* using a perfectly fine generator to generate a seed >.>"
*/
unsigned int devrand( void )
{
int f;
unsigned int r;
f=open("/dev/urandom", O_RDONLY);
if( f == -1) exit(-1); // ERROR?
if( read(f,&r,4)!=4 ) exit(-1); // ERROR?
close(f);
return r;
}
( all there upon request )
Now this works just fine without issues but if I specify my array 'password' to be of say size 9 the program starts returning values not within the 'pwd' array.
Ive had it return quotes brackets and a bunch of various non printables.
Any idea's?