Monday, 27 January 2014

Random Key Generator using Perl

When you buy new software, there usually is a license key associated with your copy.  Ever wondered, how these keys get generated? Typically, advanced products use heavily encrypted key codes, while simple old-school vintage softwares used simple keys.

In this post, I'll show you a simple script to randomly create some keys using Perl.

Keys can be generated using different combinations. You could have plain vanilla keys containing only digits or alphanumeric keys or alphanumeric keys mixed with special characters or small letters mixed with capital letters. The choice is yours.

Ok, so in this program, we ask the user to enter the desired length of keys to be generated to make it interactive.

Alternatively, you could skip the user input altogether and hardcode a specific figure for key-length. Eg: $len_str = 16

use strict;
use warnings;

print "Enter the desired length of keys to be generated : \n";

my $len_str = <STDIN>;

my $random_string =&generate_random_string($len_str);

print "$random_string \n";

sub generate_random_string() {

$len_str = shift;

my @chars = ('a'..'z', 'A'..'Z','0'..'9','-','*','%','$'); 

my $random_string;

foreach (1..$len_str) {

$random_string .= $chars[rand @chars];

}

  return $random_string;

}  #end of subroutine

The subroutine generate_random_string contains the main logic of the program. Note that we have used the rand function which is responsible for generating random characters.

Note the line above in script, in which we have mentioned the condition - to include small letters a-z, capital letters A-Z, digits 0-9 and special characters -, *, %, $. Here you could add any other character you want to.

1 comment:

  1. Iron Clad Zone: Random Key Generator Using Perl >>>>> Download Now

    >>>>> Download Full

    Iron Clad Zone: Random Key Generator Using Perl >>>>> Download LINK

    >>>>> Download Now

    Iron Clad Zone: Random Key Generator Using Perl >>>>> Download Full

    >>>>> Download LINK sb

    ReplyDelete

Related Posts Plugin for WordPress, Blogger...
eXTReMe Tracker