Password Generation
Perl is a powerful language in that it makes manipulation of nearly all types of data a breeze. What takes scores of lines with C++ or some other language like Java, can be accomplished with minimal effort in Perl. When performing cryptographic related work, this can be a valuable asset, especially when you need to generate information quickly. Let's say for example that you need to quickly generate a random password to secure your site...You could use code like this to make it happen...
sub generate_random_password
{
my $passwordsize = shift;
my @alphanumeric = ('a'..'z', 'A'..'Z', 0..9);
my $randpassword = join '',
map $alphanumeric[rand @alphanumeric], 0..$passwordsize;
return $randpassword;
}
The code is called in this manner:
$returnvalue = generate_random_password(64);
OR
$returnvalue = &generate_random_password(64);
These are the two contexts in which an unpackaged function may be called in Perl, any other method will throw an error and make your program act like it got hold of some bad LSD....anyhow... What code does is accept $passwordsize as a length argument and returns a string of the specified length using interpolation between 0 and the length passed to the function. You can also use it to generate pad files for OTP encryption. Simply pass it a password size that is symmetric to the size of the data you are encrypting and dump the contents into a file. That simple. This function is small but useful, hence I'm posting it here. Check it out, and I hope you'll find use for it.