PHP Custom encryption and Decryption program instance, PHP encryption and decryption Instance _php tutorial

Source: Internet
Author: User
Tags decrypt

PHP Custom encryption and Decryption program instance, PHP encryption and decryption instance


This article describes the PHP custom encryption and decryption program. Share to everyone for your reference. The specific analysis is as follows:

PHP3 Cryption is a very easily cracked, insecure cryptographic feature that should not be very important to use, although encryption is good and it does not hinder the rigorous testing of cutting-edge cracking programs.

However, try it ... This is a great way to encrypt and decrypt strings. With many recess functions, this is bidirectional. Based on a password, you can encrypt or decrypt it. You can also decrypt or encrypt countless times, through loops or other methods. The characters in the alphabet also change. All of these things allow you to modify and consolidate encryption.

What's the best part about this? You can encrypt and decrypt or a piece of paper and a pencil. This takes quite a bit longer, but you don't need a computer that is nearby to use it if you ever lose the code if you remember that your technology can decrypt it.

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 succeed the day after doing it suddenly comes true.

Note that this does not encrypt/decrypt invisible characters (spaces), such as line break (n) or label (TON)! I'm sorry, but I try, if you find a way, please let me know!

Copy CodeThe 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 "";

Copy the Code code as follows:
Highlight_file ("crypto.php");

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/935479.html www.bkjia.com true http://www.bkjia.com/PHPjc/935479.html techarticle PHP Custom Encryption and decryption program instance, PHP encryption and decryption example this article describes the PHP custom encryption and decryption program. Share to everyone 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.