一段php加密解密的代码
2023-06-13 09:13:43 时间
<?php
$key="Thisissupposedtobeasecretkey!!!";
functionkeyED($txt,$encrypt_key)
{
$encrypt_key=md5($encrypt_key);
$ctr=0;
$tmp="";
for($i=0;$i<strlen($txt);$i++)
{
if($ctr==strlen($encrypt_key))$ctr=0;
$tmp.=substr($txt,$i,1)^substr($encrypt_key,$ctr,1);
$ctr++;
}
return$tmp;
}
functionencrypt($txt,$key)
{
srand((double)microtime()*1000000);
$encrypt_key=md5(rand(0,32000));
$ctr=0;
$tmp="";
for($i=0;$i<strlen($txt);$i++)
{
if($ctr==strlen($encrypt_key))$ctr=0;
$tmp.=substr($encrypt_key,$ctr,1).
(substr($txt,$i,1)^substr($encrypt_key,$ctr,1));
$ctr++;
}
returnkeyED($tmp,$key);
}
functiondecrypt($txt,$key)
{
$txt=keyED($txt,$key);
$tmp="";
for($i=0;$i<strlen($txt);$i++)
{
$md5=substr($txt,$i,1);
$i++;
$tmp.=(substr($txt,$i,1)^$md5);
}
return$tmp;
}
$string="HelloWorld!!!";
//encrypt$string,andstoreitin$enc_text
$enc_text=encrypt($string,$key);
//decrypttheencryptedtext$enc_text,andstoreitin$dec_text
$dec_text=decrypt($enc_text,$key);
print"Originaltext:$string<Br>\n";
print"Encryptedtext:$enc_text<Br>\n";
print"Decryptedtext:$dec_text<Br>\n";
?>
$key="Thisissupposedtobeasecretkey!!!";
functionkeyED($txt,$encrypt_key)
{
$encrypt_key=md5($encrypt_key);
$ctr=0;
$tmp="";
for($i=0;$i<strlen($txt);$i++)
{
if($ctr==strlen($encrypt_key))$ctr=0;
$tmp.=substr($txt,$i,1)^substr($encrypt_key,$ctr,1);
$ctr++;
}
return$tmp;
}
functionencrypt($txt,$key)
{
srand((double)microtime()*1000000);
$encrypt_key=md5(rand(0,32000));
$ctr=0;
$tmp="";
for($i=0;$i<strlen($txt);$i++)
{
if($ctr==strlen($encrypt_key))$ctr=0;
$tmp.=substr($encrypt_key,$ctr,1).
(substr($txt,$i,1)^substr($encrypt_key,$ctr,1));
$ctr++;
}
returnkeyED($tmp,$key);
}
functiondecrypt($txt,$key)
{
$txt=keyED($txt,$key);
$tmp="";
for($i=0;$i<strlen($txt);$i++)
{
$md5=substr($txt,$i,1);
$i++;
$tmp.=(substr($txt,$i,1)^$md5);
}
return$tmp;
}
$string="HelloWorld!!!";
//encrypt$string,andstoreitin$enc_text
$enc_text=encrypt($string,$key);
//decrypttheencryptedtext$enc_text,andstoreitin$dec_text
$dec_text=decrypt($enc_text,$key);
print"Originaltext:$string<Br>\n";
print"Encryptedtext:$enc_text<Br>\n";
print"Decryptedtext:$dec_text<Br>\n";
?>
相关文章
- PHP多进程并行执行php脚本详解编程语言
- MySQL and PHP: Establishing the Perfect Connection(mysql链接php)
- 的数据库连接PHP与Oracle数据库的连接技术指南(php与oracle)
- PHP实现MySQL表格删除(php删除mysql表)
- PHP与MSSQL:高效开发数据驱动应用程序(php与mssql)
- php建立你的网站:使用 Apache、MySQL 和 PHP(httpdmysql)
- PHP连接MSSQL实现注册功能(php注册写入mssql)
- 在Linux环境下,使用PHP发送邮件(linux发送邮件php)
- PHP加密/解密函数dencrypt(动态密文,带压缩功能,支持中文)
- php接口类与抽象类的实际作用
- PHP变量的定义方法
- PHP中的MYSQL常用函数(php下操作数据库必备)
- 微盾PHP脚本加密专家php解密算法
- PHP和Mysqlweb应用开发核心技术第1部分Php基础-1开始了解php
- 解析如何用phpscrew加密php源代码
- 一组PHP可逆加密解密算法实例代码
- php基于mcrypt的加密解密实例