2 u014364788 u014364788 于 2014.11.22 15:17 提问

已知加密算法,密文,,求解明文

根据加密算法解密下列密文:
a2c8d394WAv3UUjYcrTEvd1LDIyix0AsEAnDmuFcbiborAyoX75g5Qg

2个回答

xuzuning
xuzuning   Ds   Rxr 2014.11.22 16:32
已采纳

噢,漏贴了结果
echo crypty('a2c8d394WAv3UUjYcrTEvd1LDIyix0AsEAnDmuFcbiborAyoX75g5Qg', 'DECODE');//GC2014%&d

xuzuning
xuzuning   Ds   Rxr 2014.11.22 16:29

echo crypty('a2c8d394WAv3UUjYcrTEvd1LDIyix0AsEAnDmuFcbiborAyoX75g5Qg', 'DECODE'); //

完备的加解密函数如下(略去了过期判断,自己补上吧)
function crypty($string, $operation = 'ENCODE', $key = 'test', $expiry = 0) {
$ckey_length = 8;
$key = md5($key ? $key : 'test');
$keya = md5(substr($key, 0, 16));
$keyb = md5(substr($key, 16, 16));
$keyc = $operation == 'ENCODE' ? substr(md5(microtime()), -$ckey_length) : substr($string, 0, $ckey_length);;
$cryptkey = $keya.md5($keya.$keyc);
$key_length = strlen($cryptkey);
if($operation == 'ENCODE') {
$string = sprintf('%010d', $expiry ? $expiry + time() : 0).substr(md5($string.$keyb), 0, 16).$string;
}else {
$string = substr($string, $ckey_length);
$string .= str_repeat('-', strlen($string) % 4);
$string = base64_decode($string);
}
$string_length = strlen($string);
$result = '';
$box = range(0, 255);
$rndkey = array();
for($i = 0; $i <= 255; $i++) {
$rndkey[$i] = ord($cryptkey[$i % $key_length]);
}
for($j = $i = 0; $i < 256; $i++) {
$j = ($j + $box[$i] + $rndkey[$i]) % 256;
$tmp = $box[$i];
$box[$i] = $box[$j];
$box[$j] = $tmp;
}
for($a = $j = $i = 0; $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 == 'ENCODE') {
return $keyc.str_replace('=', '', base64_encode($result));
}else {
return substr($result, 26);
}
}

Csdn user default icon
上传中...
上传图片
插入图片