I would like to convert this perl sub to a php function so far i havnt manage to get it working... plz help
(if ur wondering its the lock and key algorithm for making connections in direct connect)
(and no i dont want to use perl in php to make it work)
if it would help i got vb/java/c++ code for it to but this perl code is the best of them i think...
sub lock2key {
my ($lock) = @_;
my $k = ""; my $i; my $t; my $k;
my @dumcheck = split(/ /,$lock);
for ($i=0;$i<length($dumcheck[0]);$i++) {
$t=ord(substr($lock,$i,1));
if ($i == 0) {
$t=$t ^ 5;
} else {
$t=$t ^ (ord(substr($lock,$i-1,1)));
}
$t=($t+(($t % 17) * 15));
while (!($t <= 255)) {
$t=$t-255;
}
if ($t == 0) {
$k=$k."/%DCN".sprintf("%03d",$t)."%/";
} elsif ($t == 5) {
$k=$k."/%DCN".sprintf("%03d",$t)."%/";
} elsif ($t == 96) {
$k=$k."/%DCN".sprintf("%03d",$t)."%/";
} elsif ($t == 124) {
$k=$k."/%DCN".sprintf("%03d",$t)."%/";
} elsif ($t == 126) {
$k=$k."/%DCN".sprintf("%03d",$t)."%/";
} elsif ($t == 36) {
$k=$k."/%DCN".sprintf("%03d",$t)."%/";
} else {
$k=$k.chr($t);
}
}
substr($k,0,1) = chr(ord($k) ^ ord(substr($k,length($k)-1)));
return $k;
}