当前位置:Gxlcms > PHP教程 > 求一解密函数的对应加密函数

求一解密函数的对应加密函数

时间:2021-07-01 10:21:17 帮助过:8人阅读

现在已知一解密函数(readkey)如下,求对应的加密函数
function authcode( $string, $operation = "DECODE", $key = "", $expiry = 0 ){				$ckey_length = 4;				$key = md5( $key != "" ? $key : "a2264dxLupVMlkqR" );				$keya = md5( substr( $key, 0, 16 ) );				$keyb = md5( substr( $key, 16, 16 ) );				$keyc = $ckey_length ? $operation == "DECODE" ? substr( $string, 0, $ckey_length ) : substr( md5( microtime( ) ), 0 - $ckey_length ) : "";				$cryptkey = $keya.md5( $keya.$keyc );				$key_length = strlen( $cryptkey );				$string = $operation == "DECODE" ? base64_decode( substr( $string, $ckey_length ) ) : sprintf( "%010d", $expiry ? $expiry + time( ) : 0 ).substr( md5( $string.$keyb ), 0, 16 ).$string;				$string_length = strlen( $string );				$result = "";				$box = range( 0, 255 );				$rndkey = array( );				$i = 0;				for ( ;	$i <= 255;	++$i	)				{								$rndkey[$i] = ord( $cryptkey[$i % $key_length] );				}				$j = $i = 0;				for ( ;	$i < 256;	++$i	)				{								$j = ( $j + $box[$i] + $rndkey[$i] ) % 256;								$tmp = $box[$i];								$box[$i] = $box[$j];								$box[$j] = $tmp;				}				$a = $j = $i = 0;				for ( ;	$i < $string_length;	++$i	)				{								$a = ( $a + 1 ) % 256;								$j = ( $j + $box[$a] ) % 256;								$tmp = $box[$a];								$box[$a] = $box[$j];								$box[$j] = $tmp;								$result .= chr( ord( $string[$i] ) ^ $box[( $box[$a] + $box[$j] ) % 256] );				}				if ( $operation == "DECODE" )				{								if ( ( substr( $result, 0, 10 ) == 0 || 0 < substr( $result, 0, 10 ) - time( ) ) && substr( $result, 10, 16 ) == substr( md5( substr( $result, 26 ).$keyb ), 0, 16 ) )								{												return substr( $result, 26 );								}								return "";				}				return $keyc.str_replace( "=", "", base64_encode( $result ) );}function readkey( $keys ){		$Leskey = authcode( $keys, "DECODE", "a2264dxLupVMlkqR" );		$Leskey = base64_decode( $Leskey );		$firstStr = substr( $Leskey, 0, 1 );		$Leskey = substr( $Leskey, 1 );		$Leskey = strrev( substr( $Leskey, 0, $firstStr ) ).chr( ord( substr( $Leskey, $firstStr, 1 ) ) ^ $firstStr ).strrev( substr( $Leskey, $firstStr + 1 ) );		$Leskey = base64_decode( $Leskey );		$Leskey = json_decode( $Leskey, TRUE );		return $Leskey;}


加密后的字串: 正确的在2楼
561eqDNvqSI/n6UPGqb5XbORsuT9a26W6M415bRUYpP4enT5Kb/BLd5MI7Jvvt2RE35r1lHrdtC5MYNUtP7gpbqY0GeUbLXRUrUL9ABC1XTFD4zlVf3VoM4HUdEUxHAkVivkA2G1ywT2VXlLNrnuq9AXs65GXrD0G2ILS693cfGAwn4xL4QI313FVYtHWLK/EIcg0HyRMxMR5P8fftAA+Fw42c5c31G8yCh96lNfBcrhsjuO7tqJuiBSuKQBH3bbxfnum1yb1RgI8myw23tlrtdDBoPiNpCgm1usa2L+lAXLhvE8yqRLg5T8ZVXxwvO1quV8zMpBrY/XxRu5+Nn6AvXsKUwdyhVCp2jgj5S4Yr0CWcyiUg




回复讨论(解决方案)

但你的函数并不能还原你的加密串

但你的函数并不能还原你的加密串

不好意思。给错了,这段字符串

5463Y5sPLQyvMtPQhkngTjLDP0soLvmhapvAYaha3XflhpkhpVP059ow7wZ9b+TGkcVoKNM38P9TQJ4OrOQnn+xq5csI/5xB7t+x1T3W9CkKN+ocjNKQyI0yyyL4SUakFwqAJjebUICbw9JvRlidbi6awuU8PKnyR4hSOL3376WA24SjqpxGmvJ0S76+76eJt5e3CeL2PdklXdxoFWz1Nc5ZQLW0a0xpvabsBqSGAWXIhFmoa9wkP8pZHz8cDofPZjhA7GoIcCg6XWRg978Jkq3uMxT7Z5zTyY9VgW4BHvQbQZp242IDaafgGt1gVIu4rwarcCARDu+xLo74jHeJ2ZsCXHq/HvsqnQywsz8nWOwrYdZGjhlz5nExdSY7PXpicxR2q/E


我没权限改主题了。麻烦帮修改一下。

已自己搞定。。

楼主,能否分享一下对于移位的解密思路呢?

人气教程排行