#!/usr/bin/perl -w

=head1 	NAME

mkpass.pl

=head1 SYNOPSIS

mkpass.pl N

=head1 	DESCRIPTION

This program will generate a password, and provide the phontic words
for the letters, and numbers in the password seperated by "|".  The
length is determined by the "N" argument.

=head1  AUTHOR 

JD Runyan

=head2 TITLE

Mid-Range Systems Administrator

=head2 ORGINIZATION

United States Department of Agriculture(USDA) National Information Technology
Center(NITC) in Kansas City, Missouri(KCMO)

=head2 DATE

2002/06/18

=head1 BUGS

None yet, but I'm just getting started, so I'm sure that I can add some for
future releases.

=head1 COPYRIGHT

This program is free software.  You may copy or redistribute it under the same
terms as perl itself.

=cut

$pwlen = shift @ARGV;
($password,$phonetic) = mk_pass($pwlen);
print "$password => $phonetic\n";

sub mk_pass {
	# 
	# generates a random password of length $pwlen, and builds a phonetic phrase to
	# help clarify the password.  Passwords will contain upper and lower case letters
	# and numbers
	#
	$pwlen = shift;
	my %passkey = (							# hash of letters and numbers to match to the password
		0 => "zero",
		1 => "one",
		2 => "two",
		3 => "three",
		4 => "four",
		5 => "five",
		6 => "six",
		7 => "seven",
		8 => "eight",
		9 => "nine",
		A => "ALPHA",
		B => "BRAVO",
		C => "CHARLIE",
		D => "DELTA",
		E => "ECHO",
 		F => "FOXTROT",
		G => "GOLF",
 		H => "HOTEL",
 		I => "INDIA",
 		J => "JULIETT",
 		K => "KILO",
 		L => "LIMA",
 		M => "MIKE",
 		N => "NOVEMBER",
 		O => "OSCAR",
 		P => "PAPA",
 		Q => "QUEBEC",
 		R => "ROMEO",
 		S => "SIERRA",
 		T => "TANGO",
 		U => "UNIFORM",
 		V => "VICTOR",
 		W => "WHISKEY",
 		X => "X-RAY",
 		Y => "YANKEE",
 		Z => "ZULU"
	);
	foreach $LETTER (A..Z) {					# creates the lowercase version of al the letter above, and adds them to the hash
		($letter = $LETTER) =~ tr/A-Z/a-z/;
		my $UC = $passkey{$LETTER};
		(my $lc = $UC) =~ tr/A-Z/a-z/;
		$passkey{$letter} = $lc;
	}
	my @password_chars 	=  (0..9,'A'..'Z','a'..'z');			# these 4 lines generate the random password of length $pwlen
	my $num_chars		=  @password_chars;
	my $userpassword	=  '';
	$userpassword		.= $password_chars[rand($num_chars)] for (1..$pwlen);
	my $pwphonetic ="";
	my $first = 1;
	while ( $userpassword =~ /(.)/g ) { 				# creates the phonetic phrase
		if (!$first) 	{ $pwphonetic .= ' | '; }
		else		{ $first--; }
		$pwphonetic .= $passkey{$1};
	}
	return ($userpassword,$pwphonetic);				# returns the values to the calling routine
}


