Perl to PHP conversion

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zishan
    New Member
    • Feb 2007
    • 2

    Perl to PHP conversion

    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,$ch ar,$key_char,$e nc_string,$enco de,$first,
    $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($ke y,0,length($sou rce));
    while ($index < length($source) ) {
    $char = substr($source, $index,1);
    $key_char = substr($key,$in dex,1);
    $enc_string .= chr(ord($char) ^ ord($key_char)) ;
    $index++;
    }
    for (0..255) { $escapes{chr($_ )} = sprintf("%2x", $_); }
    $index=0;
    while ($index < length($enc_str ing)) {
    $char = substr($enc_str ing,$index,1);
    $encode = $escapes{$char} ;
    $first = substr($encode, 0,1);
    $second = substr($encode, 1,1);
    $let1=substr($p ub_key, hex($first),1);
    $let2=substr($p ub_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;
    }
  • Motoma
    Recognized Expert Specialist
    • Jan 2007
    • 3236

    #2
    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.

    Comment

    Working...