Luigi Auriemma

aluigi.org (ARCHIVE-ONLY FORUM!)
It is currently 19 Jul 2012 14:43

All times are UTC [ DST ]





Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: php port peerchat_ip
PostPosted: 19 Nov 2008 09:44 

Joined: 02 Mar 2008 12:21
Posts: 3
Hi,

I wish to port the ip decrypter to PHP, but i have some problems with getting the correct output. I'm just starting with php, have no knowledge of c++ and havent got much experience with bitwise operations too. In short: I need someone's help.

Code:
<?PHP

function ipdec($ipchar) {

$answer = 15;
switch ($ipchar) {
   case 'a': $answer = 0;
   case 'F': $answer = 1;
   case 'l': $answer = 2;
   case '4': $answer = 3;
   case 'u': $answer = 4;
   case 'O': $answer = 5;
   case 'D': $answer = 6;
   case '9': $answer = 7;
   case 's': $answer = 8;
   case 'f': $answer = 9;
   case 'W': $answer = 10;
   case 'q': $answer = 11;
   case '1': $answer = 12;
   case 'v': $answer = 13;
   case 'G': $answer = 14;
   }
return $answer;
}


function ipdecoder($ip) {

  $answer = 0;
  $answer |= ipdec($ip[1]) << 28;
  $answer |= ipdec($ip[2]) << 24;
  $answer |= ipdec($ip[3]) << 20;
  $answer |= ipdec($ip[4]) << 16;
  $answer |= ipdec($ip[5]) << 12;
  $answer |= ipdec($ip[6]) << 8;
  $answer |= ipdec($ip[7]) << 4;
  $answer |= ipdec($ip[8]);
  $answer ^= 0xc3801dc7;
  return $answer;
}

$ipdecode = 'XWDusGvauX';
echo long2ip(ipdecoder($ipdecode));


?>


Top
 Profile  
 
 
 Post subject: Re: php port peerchat_ip
PostPosted: 19 Nov 2008 13:02 

Joined: 13 Aug 2007 21:44
Posts: 4068
Location: http://aluigi.org
you forgot to insert the "break;" in the switch cases and to convert the big endian number in little endian before passing it to long2ip (unfortunately php doesn't seem to have a inet_ntoa function... mah).
check the attached one


Attachments:
peerchat_ip.txt [1.14 KiB]
Downloaded 105 times
Top
 Profile  
 
 Post subject: Re: php port peerchat_ip
PostPosted: 19 Nov 2008 13:19 

Joined: 02 Mar 2008 12:21
Posts: 3
awesome, thank you so much for your fast reply!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for: