By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,278 Members | 1,342 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,278 IT Pros & Developers. It's quick & easy.

Perl to PHP conversion

P: 2
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;
}
Mar 1 '07 #1
Share this Question
Share on Google+
1 Reply


Motoma
Expert 2.5K+
P: 3,235
Perhaps you could tell us what this method of encryption is called? Or explain the way the technique works?
It would be easier to rewrite the method than convert code line by line.
Mar 1 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.