PHP Custom Encryption and decryption program instances
This article mainly introduces the PHP custom encryption and decryption program, the example analysis of the custom encryption and decryption class files and related usage, with a certain reference value, the need for friends can refer to the following
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!
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 "
" . substr ($ralphabet, $j, 1). " | n "; } print "
"; for ($i =0; $i {print "
" . ($i + 1). "| | "; for ($k =0; $k {print "
" . substr ($pos _alpha_ary[$i], $k, 1). " | n "; } print "
"; } Print "
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 is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/975886.html www.bkjia.com true http://www.bkjia.com/PHPjc/975886.html techarticle PHP Custom Encryption and Decryption program example this article mainly introduces the PHP custom encryption and decryption program, the example analysis of the custom encryption and decryption class files and related usage, with a certain reference to borrow ...