Hey, I have a question. I have been learning python recently, and am wondering how I would convert some Perl code I have to python. There may not even be a way, I am just looking for any information.
Here is the perl:
(BTW This is NOT my code. It belongs to hackthissite.or g)
Here is the perl:
Code:
sub validkey {
if (not($_[0] =~ /[A-Z]|[a-z]|[0-9]/)) {
return 0;
}
my @idchars = split(//, $_[0]);
my ($total, $counter, $char) = (0, 0);
while (defined($idchars[$counter])) {
$char = $idchars[$counter];
$total += (ascii($char)+($total*$counter));
$counter++;
}
if ($total > 925559 && $total < 927901) {
return $total;
} else {
return 0;
}
}
sub ascii {
my (@str, $pos, $offset);
if ($_[0] =~ /[0-9]/) {
@str = split(//, '0123456789');
$offset = 48;
} elsif ($_[0] =~ /[A-Z]/) {
@str = split(//, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ');
$offset = 65;
} elsif ($_[0] =~ /[a-z]/) {
@str = split(//, 'abcdefghijklmnopqrstuvwxyz');
$offset = 97;
} else {
return 0;
}
$pos = 0;
while (defined($str[$pos])) {
if ($_[0] eq $str[$pos]) {
return ($pos+$offset);
}
$pos++;
}
}
Comment