Php custom encryption and decryption program

Source: Internet
Author: User

Php custom encryption and decryption program

PHP3 Cryption is a very easy-to-crack, insecure encryption function, and should not be a very important thing to use. Although encryption is good, it will not impede the rigorous test of the sophisticated cracking program.

But try it... this is a great way to encrypt and decrypt strings. It is bidirectional with many hidden nest functions. You can encrypt or decrypt a password. You can also decrypt or encrypt data multiple times through loops or other methods. The characters in the alphabet also change. All these things allow you to modify and consolidate encryption.

What is the best part? You can encrypt and decrypt a piece of paper and a pencil. This takes a long time, but you don't need a computer nearby to use it. If you have lost code, if you still remember that your technology can be decrypted.

I wrote these features in about an hour, after several unsuccessful and frustrating attempts, and gained a longer time I had no way out. The best way to achieve it that day after success is achieved.

Please note that this will not encrypt/decrypt intangible characters (spaces), such as line breaks (n) or tags (tons )! Sorry, but I tried. If you find a solution, please let me know!
*/
Highlight_file ("crypto. php tutorial ");

$ Ralphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890 !,. :;?~ @ # $ % ^ & * () _ +-=] [} {/> <"'";
$ Alphabet = $ ralphabet. $ ralphabet;


Class Crypto {

Function encrypt ($ password, $ strtoencrypt ){

Global $ ralphabet;
Global $ alphabet;

For ($ I = 0; $ I <strlen ($ password); $ I ++)
{
$ Cur_ps tutorial wd_ltr = substr ($ password, $ I, 1 );
$ Pos_alpha_ary [] = substr (strstr ($ alphabet, $ cur_pswd_ltr), 0, strlen ($ ralphabet ));
}

$ I = 0;
$ N = 0;
$ Nn = strlen ($ password );
$ C = strlen ($ strtoencrypt );

While ($ I <$ c)
{
$ Encrypted_string. = substr ($ pos_alpha_ary [$ n], strpos ($ ralphabet, substr ($ strtoencrypt, $ I, 1), 1 );

$ N ++;
If ($ n = $ nn) $ n = 0;
$ I ++;
}

Return $ encrypted_string;

}

 


Function decrypt ($ password, $ strtodecrypt ){

Global $ ralphabet;
Global $ alphabet;

For ($ I = 0; $ I <strlen ($ password); $ I ++)
{
$ Cur_pswd_ltr = substr ($ password, $ I, 1 );
$ Pos_alpha_ary [] = substr (strstr ($ alphabet, $ cur_pswd_ltr), 0, strlen ($ ralphabet ));
}

$ I = 0;
$ N = 0;
$ Nn = strlen ($ password );
$ C = strlen ($ strtodecrypt );

While ($ I <$ c)
{
$ Decrypted_string. = substr ($ ralphabet, strpos ($ pos_alpha_ary [$ n], substr ($ strtodecrypt, $ I, 1), 1 );

$ N ++;
If ($ n = $ nn) $ n = 0;
$ I ++;
}

Return $ decrypted_string;


}


Function cryption_table ($ password ){

Global $ ralphabet;
Global $ alphabet;

For ($ I = 0; $ I <strlen ($ password); $ I ++)
{
$ Cur_pswd_ltr = substr ($ password, $ I, 1 );
$ Pos_alpha_ary [] = substr (strstr ($ alphabet, $ cur_pswd_ltr), 0, strlen ($ ralphabet ));
}


Print "<table border = 1 cellpadding =" 0 "cellspacing =" 0 "> n ";

Print "<tr> <td> </td> ";
For ($ j = 0; $ j <strlen ($ ralphabet); $ j ++)
{
Print "<td align =" center "> <font size =" 2 "face =" arial "> ". substr ($ ralphabet, $ j, 1 ). "</td> n ";
}
Print "</tr> ";


For ($ I = 0; $ I <count ($ pos_alpha_ary); $ I ++)
{
Print "<tr> <td align =" right "> <font size =" 2 "> <B> ". ($ I + 1 ). "| </B> </font> </td> ";
For ($ k = 0; $ k <strlen ($ pos_alpha_ary [$ I]); $ k ++)
{
Print "<td align =" center "> <font size =" 2 "face =" arial "> ". substr ($ pos_alpha_ary [$ I], $ k, 1 ). "</td> n ";
}
Print "</tr> ";
}

Print "</table> n ";

}

} // End class Crypto

// Example written by Macro Zeng
// The motto of the network technology supervisor: the trio must have our teacher. Http://www.bkjia.com
$ Ct = new Crypto;
// $ Ct-> cryption_table ($ password );
Echo "<form action = $ PHP_SELF method = post> ";
If ($ mod = 2 ){
$ Strtodecrypt = $ ct-> encrypt ($ password, $ strtoencrypt );
Echo 'encryption String (Encrypted field ):';
Echo "<input type = text name = strtodecrypt size = 45 value = $ strtodecrypt>
";
Echo "password lock: <input type = text name = password size = 6 value = $ password> ";
Echo "<input type = submit value =" Decrypt (decryption) "> ";
}
Else {
$ Strtoencrypt = $ ct-> decrypt ($ password, $ strtodecrypt );
Echo 'string to Encrypt (the field to be encrypted ):';
Echo "<input type = text name = strtoencrypt size = 45 value = $ strtoencrypt>
";
Echo "password lock: <input type = text name = password size = 6 value = $ password> ";
Echo "<input type = submit value =" Encrypt (encrypted) "> ";
Echo "<input type = hidden name = mod value = 2> ";
}
Echo "</form> ";

 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.