Php custom encryption and decryption program instance, php encryption and decryption instance _ PHP Tutorial

Source: Internet
Author: User
Php custom encryption and decryption program instance, php encryption and decryption instance. Php custom encryption and decryption program instance, php encryption and decryption instance this article describes the php custom encryption and decryption program. Share it with you for your reference. The specific analysis is as follows: P php custom encryption and decryption program instance, php encryption and decryption instance

This example describes the php custom encryption and decryption program. Share it with you for your reference. The specific analysis is as follows:

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 hinder the strict test of sophisticated cracking programs.

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!

The code is as follows:

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

Class Crypto {

Function encrypt ($ password, $ strtoencrypt ){

Global $ ralphabet;
Global $ alphabet;

For ($ I = 0; $ 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 ($ 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 {
$ 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 {
$ Cur_pswd_ltr = substr ($ password, $ I, 1 );
$ Pos_alpha_ary [] = substr (strstr ($ alphabet, $ cur_pswd_ltr), 0, strlen ($ ralphabet ));
}

Print"


















N "; Print" ";For ($ j = 0; $ j{Print" N ";}Print" "; For ($ I = 0; $ I{Print" ";For ($ k = 0; $ k{Print" N ";}Print" ";} Print"
". Substr ($ ralphabet, $ j, 1 )."
". ($ I + 1)." |". Substr ($ pos_alpha_ary [$ I], $ k, 1 )."
N ";

}

} // End class Crypto

// Example written by Macro Zeng
$ Ct = new Crypto;
// $ Ct-> cryption_table ($ password );
Echo "";

The code is as follows:


Highlight_file ("crypto. php ");

I hope this article will help you with php programming.

Examples in this article describes the php custom encryption and decryption program. Share it with you for your reference. The specific analysis is as follows: P...

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.