Jump to content

Simple Obfuscation of .txt file


highlander141

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
https://forums.phpfreaks.com/topic/283856-simple-obfuscation-of-txt-file/
Share on other sites

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>';

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.