实验吧-杂项-你没有见过的加密!(php srand()和rand()函数)

时间:2019-02-21
本文章向大家介绍实验吧-杂项-你没有见过的加密!(php srand()和rand()函数),主要包括实验吧-杂项-你没有见过的加密!(php srand()和rand()函数)使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

什么垃圾东西,弄半天,Windows上运行乱码,linux上7.3的php运行也是乱码(气死)。

下载文件,查看内容

<?php


	function encrypt($str)
	{
		$cryptedstr = "";
		srand(3284724);
		for ($i =0; $i < strlen($str); $i++)
		{
			$temp = ord(substr($str,$i,1)) ^ rand(0, 255);
			while(strlen($temp)<3)
			{
				$temp = "0".$temp;

			}
			$cryptedstr .= $temp. "";
		}
		return base64_encode($cryptedstr);
	}
	
?>

就顺着加密思路写解密代码:

<?php
$cryptedstr = "MDEzMjE5MDAyMTg0MTUzMjQwMTQ0MDc3MjUzMDk2MTc1MTUzMTE4MTg4MDEwMDA2MTg4MDA0MjM4MDI1MTA3MTU4MTc5MTM4";
$cryptedstr = base64_decode($cryptedstr);

$len = strlen($cryptedstr);
$str = "";
srand(3284724);
for($i=0;$i<$len/3;$i++){
	$temp = substr($cryptedstr, 0, 3);
	$cryptedstr = substr($cryptedstr, 3);
	$n = intval($temp)^rand(0, 255);
	$str .= chr($n);
}

echo "$str";



?>

气死了,最后在这里运行才拿到flag:http://www.dooccn.com/php/

知识点:1)srand()和rand()

参考:https://blog.csdn.net/zz_Caleb/article/details/87829463

2)substr()

参考:https://blog.csdn.net/zz_Caleb/article/details/87829892