Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Are you sure it's perl that's wrong? PHP is giving some weird results. I've added a print in both perl and php:

print "^:" . strlen($password ^ substr($enc_text, 0, $iv_len)) . "\n";

(s/strlen/length/ in perl of course), and the result in PHP is 4 instead of the expected 16. Adding a few more lines:

for ($x=0; $x<$iv_len; $x++) { printf("%02x ", ord(substr($enc_text,$x +,1))); } print "\n"; for ($x=0; $x<$iv_len; $x++) { printf("%02x ", ord(substr($password,$x +,1))); } print "\n"; for ($x=0; $x<$iv_len; $x++) { printf("%02x ", ord(substr($password,$x +,1))^ord(substr($enc_text,$x,1))); } print "\n";

shows what's going on. Output of those lines on both the perl and php versions shows:

5c 79 e1 71 1c cc ba 8e b7 46 aa 99 99 bc 56 d6 74 65 73 74 00 00 00 00 00 00 00 00 00 00 00 00 28 1c 92 05 1c cc ba 8e b7 46 aa 99 99 bc 56 d6

Looks like PHP is truncating the XOR when the shortest string run out, in this case your password, "test". Quick and dirty hack to make perl return the same result is:

sub md5_decrypt { my $iv_len = 16; my $enc_text = decode_base64(shift); my $password = shift; my $n = length($enc_text); my $i = $iv_len; my $plain_text; my $iv = substr($password ^ substr($enc_text,0,length($password)), + 0, 512); my $x; while ($i < $n) { my $block = substr($enc_text, $i, 16); $plain_text .= $block ^ pack('H*', md5_hex($iv)); $iv = substr($block . $iv, 0, length($password)) ^ $password; $i += 16; } #$plain_text =~ s/\x13\x00*$//; return $plain_text; }

But somehow I doubt that's actually the right thing to do.

In reply to Re: port a function from php by Crackers2
in thread port a function from php by reqnode

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2022-09-26 14:57 GMT
Find Nodes?
    Voting Booth?
    I prefer my indexes to start at:

    Results (117 votes). Check out past polls.