
gsr
New User
Oct 18, 2007, 9:20 AM
Post #2 of 5
(419711 views)
|
Well, some one send me the code below and said that it reads a text file with 2 arrays, the 1st array has a normal character and the second has a HEX chrs, and return false if both aare different. Here is the code $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; }; Could some of you guys explained to me? I cannot understand much, but this person also is new at Perl. Regards, Gerard
|