How to Encrypt HTML Script

By . Category: javascript, PHP, Web Tags: , ,

irnanto.comTo secure a web there are many ways that often do, one of which is to encrypt the file or encrypt the data HTML. Many people may ask why the HTML code should be encrypted ? , For me it does not really matter to encrypt files or HTML data, because the HTML code located on the user that can be viewed easily using a browser. But some people want to secure a specific HTML code on his website in order not copy and paste easily by others.

Encrypt this HTML code using PHP programming language to download the script generates HTML to be displayed into the encryption codes that will be translated or decrypt again in the browser using javascript programming language. The decryption process is used to translate the HTML code that has been encrypted into the actual HTML code without displaying the original HTML code.

Process of encrypt and decrypt requires key that serves as a reference for the process of encryption and decryption process. Key is like a key to get in and out of a house, to secure our homes should be closed and locked the house with the same key when going into or open house. When a key entry and exit is not the same as the door of the house so we could not enter the house.

Similarly, when the encryption process, the key is used to provide an identification in making the encryption code as a reference appetizer or decrypt the code at the time of HTML code have been displayed in the browser. So the key used to secure or encryption must be the same as the key that will be used to unlock or decrypt the code.

Illustration Expressions See Encryption HTML Web

illustration expressions see encryption HTML web

How Encryption Process HTML Code

It is beginning to prepare the HTML script that will be encrypted and makes the program of the encryption automatically generate such code below.

    $post_object=”[script HTML yang akan di enkripsi]”;
    $key = substr($_SERVER[‘SERVER_NAME’] , 0,4);
    for($i=0;$i< strlen($key);$i++){
        $ubah_key = $ubah_key + ord(substr($key,$i,1));
    if($ubah_key > 0){
        if(strlen($post_object) > 0){
            for($i=0;$i < strlen($post_object);$i++){
                $geser = ord(substr($post_object,$i,1)) + $ubah_key;
                if($geser > 99){
                    $hasil_geser = $hasil_geser . (string)$geser;
                    $hasil_geser = $hasil_geser . “0” . (string)$geser;
    $hasil_geser = ‘<script language=”javascript”> document.write(dec(“‘. $hasil_geser .'”))</script>’;
    echo $hasil_geser;

Explanation of encryption programs above are:

  • Second row, an HTML script variable placeholders which will be encrypted
  • The third row, making key based on the domain name in the capture characters from the first character to character to four
  • Row four, five and six is ​​an auxiliary variable
  • Seventh row, looping as many as the number of key characters
  • Lines to eight, changing each key character into ASCII characters and add
  • Lines to ten, check the contents key if greater than 0 then it will proceed to the next process
  • Eleventh row, calculate the length of a character from the variable $ post_object that holds the HTML code and check if the character length is greater than 0 then it will proceed to the next process
  • Line to twelve, looping long as the HTML code that will be encrypted
  • Line to thirteen, change each character into ASCII code and add with a key that has been changed before ($ubah_key) and in capacity to the variable $ shear
  • Line to fourteen, check if the variable $ shear is greater than 99 then the line to fifteen on the run and if it does not line seventeenth run
  • Line to fifteen, change $ scroll to the string and menggabunggan with variable $hasil_geser and stored in the variable $hasil_geser
  • Seventeenth row, adding character 0 at the beginning of the variable $shear that has been converted to a string and menggabunggan with variable $ hasil_geser and stored in the variable $hasil_geser
  • Line twenty-two, put the variable (contents) $hasil_geser into the string in the variable $ hasil_geser (string form of java script that is used to perform the function dec (decrypt) and display)
  • Line twenty-three, showing the contents of the variable $hasil_geser

How to Decrypt HTML Script

Decryption process will run in the browser after the encryption code is distributed to the browser and to execute the decryption process in the browser javascript code is needed in order to translate the encryption code that has been previously distrubusikan. Decrypt program as below.

<script language=”javascript”>
  function dec(txt){
    kp = 0;
    var j=3;
    var temp1;
    var hasil=””;
    var domain = document.domain.toLowerCase().replace(“www.”,””);
    var k = domain.substring(0,4);
    for(i=0;i<k.length;i++) {
        kp = kp + k.charCodeAt(i);
        if(txt.length >0){
                var temp= txt.substring(i, j);
                temp1 = (parseInt(temp , 10) – kp);
                j += 3;
    return hasil;

Explanation of the above decryption program are:

  • The second line makes dec function with one parameter
  • Row three, four, five, and six are auxiliary variables
  • Lines to seven take the domain name and change it to lowercase and mereplace if any subdomain www.
  • Eight lines to take fourth character of the variable domain starting from the first sequence and stored in the variable k
  • Line to nine looping long as the character of the variable k
  • Ten rows to change each character in the variable k into ASCII and added to the variable kp
  • Line to twelve check if the variable “kp” is greater than 0 then it will proceed to the next variable
  • Line to thirteen, calculate the length of characters of the parameters passed and check if greater than 0 then it will proceed to the next variable
  • Line to fourteen looping as many as “n” with the terms “i” is less than the length of the character parameter “txt” and increments +3
  • Line to fifteen take the character “txt” of 1 as j (three) and then stored in the variable temp
  • Sixteen lines to change the temp variables and converted to decimal format into integer and reduced variable kp and saved to the variable temp1
  • Line to seventeen change into a string variable temp1 original character
  • Line to eighteen increment j = j + 3
  • Twenty-two lines returns the value of the function in the form of variable content results

Finally finished the discussion of HTML Script How to Encrypt and decrypt HTML way. May be useful.

No comments yet untuk “How to Encrypt HTML Script”

Tinggalkan Komentar