Hi there,
I am Gerard, 1st year student of Perl at the university.
I came across some lines of code from a script done by an ex student that left uni and did not left any explanation of the code.
The only thing I know is that the script reads an external file that contains 2 lines of code.
The 1st and 2nd lines on this file are:
BEGIN!! Addr:* Name:John
-
4DZWJMZMX44ZiaZ4 END!!
I think it compares both lines on the script and return true if equal.
Could some one please explain me better, and how can I create the second line? is it in HExadecimal or what?
Below is the code on the script:
-
-
$const{'code_validate'} = sub {
-
my $p_decode = sub {
-
local $_;
-
my $code = defined($_[0]) ? $_[0] : '';
-
my %map = ();
-
my $i = 0;
-
foreach (48..57,65..90,97..122) {
-
$map{chr($_)} = $i % 16;
-
$i++;
-
}
-
$code =~ s!\s|\r|\n|\015|\012!!sg;
-
my $text = '';
-
my $frag = '';
-
$i = 0;
-
while ($frag = substr($code, $i, 2)) {
-
$i += 2;
-
my $chn = 16 * $map{substr($frag,0,1)};
-
$chn += $map{substr($frag,1,1)};
-
my $ch = chr($chn);
-
$text .= $ch;
-
}
-
$text = unpack('u',$text);
-
return $text;
-
};
-
local $_;
-
my $code = defined($_[0]) ? $_[0] : '';
-
return 0 unless ($code);
-
my $is_valid = 0;
-
$code =~ s!BEGIN!!sg;
-
$code =~ s!END!!sg;
-
if ($code =~ m!^\s*(.*)\s*\-\s*(.*?)\s*$!s) {
-
my ($pub, $pri) = ($1,$2);
-
$pri = &$p_decode($pri);
-
$pub =~ s!(\s|\r|\n)!!sg;
-
$pri =~ s!(\s|\r|\n)!!sg;
-
if ($pub eq $pri) {
-
$is_valid = 1;
-
}
-
}
-
return $is_valid;
-
};
-
Thanks for all your help
Gerard