Hello,
I need help in converting following perl script functions into php, can anyone pls?
sub Encrypt {
my ($source,$key,$pub_key) = @_;
my ($cr,$index,$char,$key_char,$enc_string,$encode,$f irst,
$second,$let1,$let2,$encrypted,$escapes) = '';
$source = &rot13($source);
$cr = '·¨*';
$source =~ s/[\n\f]//g;
$source =~ s/[\r]/$cr/g;
while ( length($key) < length($source) ) { $key .= $key }
$key=substr($key,0,length($source));
while ($index < length($source)) {
$char = substr($source,$index,1);
$key_char = substr($key,$index,1);
$enc_string .= chr(ord($char) ^ ord($key_char));
$index++;
}
for (0..255) { $escapes{chr($_)} = sprintf("%2x", $_); }
$index=0;
while ($index < length($enc_string)) {
$char = substr($enc_string,$index,1);
$encode = $escapes{$char};
$first = substr($encode,0,1);
$second = substr($encode,1,1);
$let1=substr($pub_key, hex($first),1);
$let2=substr($pub_key, hex($second),1);
$encrypted .= "$let1$let2";
$index++;
}
return $encrypted;
}
sub rot13{
my $source = shift (@_);
$source =~ tr /[a-m][n-z]/[n-z][a-m]/;
$source =~ tr /[A-M][N-Z]/[N-Z][A-M]/;
$source = reverse($source);
return $source;
}