Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^3: port a function from php

by Crackers2 (Parson)
on Dec 10, 2013 at 20:01 UTC ( [id://1066497]=note: print w/replies, xml ) Need Help??


in reply to Re^2: port a function from php
in thread port a function from php

Hmm I'm not getting an issue with that particular example; it's coming out f234fgerg5g for me.

I did say it was a quick hack though :)

To really emulate php you'd probably want to create a new function, something like:

sub php_xor { my ($p1,$p2) = @_; my $len = length($p1) < length($p2) ? length($p1) : length($p2); return substr($p1,0,$len) ^ substr($p2,0,$len); }

and use that where you currently have ^, giving something like:

use MIME::Base64; use Digest::MD5 qw(md5 md5_hex md5_base64); use strict; sub php_xor { my ($p1,$p2) = @_; my $len = length($p1) < length($p2) ? length($p1) : length($p2); return substr($p1,0,$len) ^ substr($p2,0,$len); } 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(php_xor($password,substr($enc_text,0,$iv_len)), 0, + 512); my $x; while ($i < $n) { my $block = substr($enc_text, $i, 16); $plain_text .= $block ^ pack('H*', md5_hex($iv)); $iv = php_xor(substr($block . $iv, 0, 512),$password); $i += 16; } #$plain_text =~ s/\x13\x00*$//; return $plain_text; } print md5_decrypt('2EC0KFZ1aGghEdySB+5Y9nbAfMrk9ky/89vwlA4HyTU=', '34g +iu34hgiu34hg') . "\n";

Replies are listed 'Best First'.
Re^4: port a function from php
by reqnode (Novice) on Dec 10, 2013 at 20:07 UTC
    Ahh it works now!!! THANK YOU SO MUCH , YOU ARE THE BEST

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1066497]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-04-16 16:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found