Jump to content

Simple Obfuscation of .txt file


highlander141
Go to solution Solved by Barand,

Recommended Posts

I am trying to use this code for simple obfuscation. But I presume nothing is returned to the function. Here's the code:

<?php
    $source = "setup.txt";
    $destination = "setup.ini";
    function enc($temp)
    {
      $len = strlen($temp);
      for($i=0;$i<$len;$i++)
      {
        $ch = $temp[$i];
        $ch = ~$ch;
        $temp[$i]=$ch;
      }
    }
    function createid($src,$dest)
    {
      $handle_1 = fopen($src, "rb");
      $handle_2 = fopen($dest,"rb");
      while(!feof($handle_1))
      {
        $Byte = fgetc($handle_1);
        sprintf($tmp,"%c",$Byte);
        enc($tmp);
$len = strlen($tmp);
        $newByte = $tmp[0];
        fputs($newByte,$handle_2);
      }
      fclose($handle_1);
      fclose($handle_2);
    }
    createid($source,$destination);
?>

 

Link to comment
Share on other sites

  • Solution

You seem to be over-complicating

$in = 'test1.txt';
$out = 'test2.txt';

/********
* obfuscate
*/
$txt = file_get_contents($in);
$str = '';
for ($i=0, $k=strlen($txt); $i<$k; $i++) {
    $str .= ~$txt[$i];
}
file_put_contents($out, $str);

/*******
* output obfuscated text
*/
echo '<pre><hr>';
readfile($out);

/*******
* output deobfuscated text
*/
echo '<hr>';

$txt = file_get_contents($out);
for ($i=0, $k=strlen($txt); $i<$k; $i++) {
    echo ~$txt[$i];
}

echo '</pre>';
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.