Author Topic: PHP encoding  (Read 1131 times)

Offline Zeggy

  • Global Moderator
  • Level 35
  • *****
  • Posts: 1,187
  • Reputation: +13/-4
    • View Profile
PHP encoding
« on: April 06, 2008, 01:39:39 PM »
I'm trying to make a simple PHP encoder for no reason at all :) (Could come in useful some day though...)

Here's what I got so far:

<?php
$compressed 
stripslashes($_POST['code']);

for (
$i 1$i <= 10$i++) {
	
$compressed gzdeflate($compressed9);
	
$compressed chunk_split(base64_encode($compressed));
	
$compressed "eval(gzinflate(base64_decode('" $compressed "')));";
}
?>

<form method="post" action="encode.php">
<textarea style="width: 900px; height: 600px;" name="code"><?=$compressed?></textarea>
<br />
<input type="submit" value="Encode!" />
</form>


It doesn't really do much, just uses base64 and gzdeflate to 'encode' chunks of code.
I'm wondering, what else could I do to improve the encoding process? I've seen some other encoders (http://www.rightscripts.com/phpencode/index.php), and they seem to generate some extra code to confuse you.

Offline Wakish

  • Level 14
  • *
  • Posts: 111
  • Reputation: +0/-1
    • View Profile
    • Wakish Wonderz
Re: PHP encoding
« Reply #1 on: May 04, 2008, 05:06:09 AM »
I'm trying to make a simple PHP encoder for no reason at all :) (Could come in useful some day though...)

Here's what I got so far:

<?php
$compressed 
stripslashes($_POST['code']);

for (
$i 1$i <= 10$i++) {
	
$compressed gzdeflate($compressed9);
	
$compressed chunk_split(base64_encode($compressed));
	
$compressed "eval(gzinflate(base64_decode('" $compressed "')));";
}
?>

<form method="post" action="encode.php">
<textarea style="width: 900px; height: 600px;" name="code"><?=$compressed?></textarea>
<br />
<input type="submit" value="Encode!" />
</form>


It doesn't really do much, just uses base64 and gzdeflate to 'encode' chunks of code.
I'm wondering, what else could I do to improve the encoding process? I've seen some other encoders (http://www.rightscripts.com/phpencode/index.php), and they seem to generate some extra code to confuse you.

Zeggy that's a cool thought..
But when encoding a our php game codes, it there any effect on the speed of execution or loading time?
I mean the time taken for the server to decode the codes and then run it..etc

Offline Zeggy

  • Global Moderator
  • Level 35
  • *****
  • Posts: 1,187
  • Reputation: +13/-4
    • View Profile
Re: PHP encoding
« Reply #2 on: May 04, 2008, 12:03:30 PM »
Well, personally, I wouldn't recommend encoding your code unless you're gonna distribute it, and if you are, a commercial solution would be much better.

Yes, my way of encoding does have quite a large effect on the speed of execution because it needs to decode the code first.

Offline greendots

  • Level 3
  • *
  • Posts: 8
  • Reputation: +0/-0
    • View Profile
Re: PHP encoding
« Reply #3 on: May 16, 2008, 12:47:14 PM »
Overhead is very high, but not all data needs to be encoded.

You can research other types of encoding, for speed or security depending on what your needs are, and be selective of which data needs encoded.  Remember you dont always need encode/decode, there are uses for secure 1-way encryption also (think md5/sha1 password storage but there are other uses).

Offline Zeggy

  • Global Moderator
  • Level 35
  • *****
  • Posts: 1,187
  • Reputation: +13/-4
    • View Profile
Re: PHP encoding
« Reply #4 on: May 16, 2008, 01:19:49 PM »
btw, there is a slightly updated code to this:

Code: [Select]
<?php
$compressed 
stripslashes($_POST['code']);

$newline   = array("\r\n""\n""\r");
$replace ' ';

$compressed str_replace($newline$replace$compressed);

$code token_get_all($compressed);
$new_code "";

foreach(
$code as $token)
{
if ($token == ";")
{
$new_code .= $token;
}
else
{
$name token_name(intval($token[0]));
if ($name != "T_COMMENT" &&
$name != "T_ML_COMMENT" &&
$name != "T_OPEN_TAG" &&
$name != "T_CLOSE_TAG")
{
$new_code .= $token[1];
}
else
{
//echo $name . " thrown away.<br />";
}
}
}

for (
$i 1$i <= 10$i++) {
$compressed gzdeflate($new_code9);
$compressed chunk_split(base64_encode($compressed));
$compressed "eval(gzinflate(base64_decode('" $compressed "')));";
}
?>


<form method="post" action="encode.php">
<textarea style="width: 900px; height: 600px;" name="code"><?=$compressed?></textarea>
<br />
<input type="submit" value="Encode!" />
</form>

I changed it so it strips out comments and extra stuff that's not needed.

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal