Close

Results 1 to 4 of 4

Thread: Java to PHP

  1. #1
    DF VIP Member
    canardo's Avatar
    Join Date
    Jul 2001
    Location
    uk
    Posts
    840
    Thanks
    0
    Thanked:        0
    Karma Level
    321

    Default Java to PHP

    Code:
    private static String decrypt2(long message,int key1,int key2){
            StringBuffer output=new StringBuffer();
            
    	message=message^key1;
            int length=(byte)(message);        
            byte input[]=new byte[length];
            for (int i=length-1;i>=0;i--){            
                message=message>>8;
                input[i]=(byte)(message^key2);
            }             
            for (int i=0;i<length;i++){            
                output.append((char)input[i]);
               //System.out.println("\toutput: "+(byte)input[i]);
            }
            return output.toString();
        }
    Could really do with the above code being converted into php, one question thats stopping me doing it myself is how can I get the byte blocks in a language that only gives me $var

    Thanks for any help

  2. #2
    DF VIP Member
    canardo's Avatar
    Join Date
    Jul 2001
    Location
    uk
    Posts
    840
    Thanks
    0
    Thanked:        0
    Karma Level
    321

    Default Re: Java to PHP

    Code:
    <?php
    
    function decrypt($message)
    {
    	$key1 = 23555;
    	$key2 = 77;
    
    	$output = "";
    
    	$length = $message & 0xFF;
    	echo $length;
    	for($i = $length-1; $i>=0; $i--)
    	{
    		$message >>= 8;
    		$output = ($message ^ $key2).$output;
    	}
    	return $output;
    }
    
    $m = 9186913876452331524;
    $var = decrypt($m);
    echo "<br /> decrypt".$m.") <br /> = ". $var ;
    
    ?>
    length unfortunately is 0 which bit is it that php doesnt like the & or the 0xff

  3. #3
    DF Probation Fusen's Avatar
    Join Date
    Mar 2004
    Location
    Kent Uni
    Posts
    3,672
    Thanks
    0
    Thanked:        0
    Karma Level
    566

    Default Re: Java to PHP

    try

    Code:
    $length = $message . 0xFF;
    you'll then get output, if it's actually the output you want is a different matter ;P
    Last edited by Fusen; 26th November 2006 at 06:19 PM.
    [CENTER][FONT=Verdana][SIZE=2]Real pirates don't [I]STEAL[/I], they [/SIZE][/FONT][B][FONT=Verdana][SIZE=2]SHARE[/SIZE][/FONT]
    [/B][SIZE=1]Unless they are cunts, then they just leech...:happy:[/SIZE][/CENTER]

  4. #4
    DF VIP Member
    canardo's Avatar
    Join Date
    Jul 2001
    Location
    uk
    Posts
    840
    Thanks
    0
    Thanked:        0
    Karma Level
    321

    Default Re: Java to PHP

    haha not quite unforunately cheers though fusen

    for anyone thats interested got it done in the end
    Code:
    <?php
    
    function decrypt($message)
    {
    	$key1 = 23555;
    	$key2 = 77;
    
    	$output = "";
    
    	echo "original message as hex = ".dechex($message)."<br><br>";
    
    	$message ^= $key1;
    	$length = $message & 255;
    
    	echo "xor'd message as hex = ".dechex($message)."<br><br>";
    
    	echo "length=".$length."<br>";
    	for($i = 0; $i<$length; $i++){
    		$message >>= 8;
    		$input = ($message ^ $key2) & 255;
    		echo "message = ".dechex($message)."<br>";
    		echo "input = ".$input."<br>";
    		$output = chr($input).$output;
    	}
    	return $output;
    }
    
    echo "decrypt(".$m.") = '".decrypt($m)."'";
    
    ?>

Similar Threads

  1. J2ME / JBlend Java on Sharp GX10 ???
    By hummmm in forum Programming
    Replies: 0
    Last Post: 25th November 2002, 01:45 AM
  2. Java Popup's :()
    By Dragoncity in forum The Dog and Duck
    Replies: 0
    Last Post: 7th October 2002, 04:16 PM
  3. Java console??
    By Jaffa in forum PC Problems
    Replies: 3
    Last Post: 26th September 2002, 02:14 AM
  4. Java Idea?
    By Roo in forum Unlocking Questions & Solutions
    Replies: 0
    Last Post: 8th September 2002, 06:55 PM

Social Networking Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •