<?php
/*Skrypt pochodzi z książki "PHP. 101 praktycznych skryptów"
  autor: Marcin Lis                    http://marcinlis.com*/
function encode($file)
{
  if(!$fd = @fopen("$file", "r")){
    echo("Nie mogę otworzyć pliku: $file");
    return false;
  }
  $size = filesize($file);
  if(!($enc = fread($fd, $size))){
    echo("Nie mogę odczytać pliku: $file");
    fclose($fd);
    return false;
  }
  fclose($fd);
  $enc = strrev($enc);
  $len = strlen($enc);

  $enc = str_replace("<", "0~54", $enc);
  $enc = str_replace(">", "0~14", $enc);
  $enc = str_replace(":", "0~83", $enc);
  $enc = str_replace("=", "0~09", $enc);
  $enc = str_replace("\"", "0~A1", $enc);
  $enc = str_replace("'", "0~1F", $enc);
  $enc = str_replace(".", "0~43", $enc);
  $enc = str_replace(";", "0~0F", $enc);
  $enc = str_replace("&", "0~EC", $enc);
  $enc = str_replace("/", "0~FD", $enc);
  $enc = str_replace("_", "0~A9", $enc);
  $enc = str_replace("\t", "0~6A", $enc);
  $enc = str_replace("\n\r", "0~C4", $enc);

  $out = "<script type=\"text/javascript\">";
  $out .= "var x=\"$enc\";";
  $out .= "x = x.replace(/0~54/g, '<');";
  $out .= "x = x.replace(/0~14/g, '>');";
  $out .= "x = x.replace(/0~83/g, ':');";
  $out .= "x = x.replace(/0~09/g, '=');";
  $out .= "x = x.replace(/0~A1/g, '\"');";
  $out .= "x = x.replace(/0~1F/g, \"'\");";
  $out .= "x = x.replace(/0~43/g, '.');";
  $out .= "x = x.replace(/0~0F/g, ';');";
  $out .= "x = x.replace(/0~EC/g, '&');";
  $out .= "x = x.replace(/0~FD/g, '/');";
  $out .= "x = x.replace(/0~A9/g, '_');";
  $out .= "x = x.replace(/0~6A/g, '\\t');";
  $out .= "x = x.replace(/0~C4/g, '\\n\\r');";

  $out .= "var xx=\"\";for(i=x.length-1;i>0;i--){";
  $out .= "xx+=x.charAt(i);};";

  $out .= "document.write(xx);";
  $out .= "</script>";

  /*if(!$fd = @fopen("$file.enc", "w")){
      echo("Błąd przy próbie otwarcia pliku: $file.enc");
      return false;
  }
  fwrite($fd, $out);
  fclose($fd);*/
  return $out;
}
echo(encode("index.html"));
?>
