PHP Custom Encryption and Decryption program example _php tips

Source: Internet
Author: User
Tags decrypt

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 easy to crack, unsafe encryption function, should not be very important things to use, although encryption is good, it will not hinder the rigorous testing of cutting-edge cracking procedures.

But, 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 are also changed. All these things allow you to modify and consolidate encryption.

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

I write about one of these features in about an hour, after several unsuccessful and frustrating attempts, and get a longer time I have no way out. A successful day after the best way to do it suddenly realized.

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

Copy Code code as follows:
$ralphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890!,.:;? ~@#$%^&* () _+-=][}{/>< "'";
$alphabet = $ralphabet. $ralphabet;

Class Crypto {

function Encrypt ($password, $strtoencrypt) {

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 ($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 "&LT;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 "&LT;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
$CT = new Crypto;
$ct->cryption_table ($password);
echo "<form action= $PHP _self method=post>";
if ($mod = = 2) {
$strtodecrypt = $ct->encrypt ($password, $strtoencrypt);
Echo ' Encrypted 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 (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>";

Copy Code code as follows:

Highlight_file ("crypto.php");

I hope this article will help you with your PHP program design.

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.