PHP 异或 算法

PHP 异或 算法

/**
     * PHP字符串“异或”算法
     * param    array   key
     * @param Request $request
     * @return mixed|string|void
     */
    public function setSecretKey(Request $request){
        $keyArr = $request->input('key');
        if(!is_array($keyArr) || empty($keyArr))
            return;
        foreach ($keyArr as $v){
            if(empty($v) || (strlen($v) != 32)){
                return;
            }
        }
        if(count($keyArr) == 1)
            return $keyArr[0];
        $arrLength = count($keyArr);
        $initKey = "00000000000000000000000000000000";
        $initKeyArr = str_split($initKey);
        for($i = 0;$i < $arrLength;$i++){
            $newKey = '';
            for($j = 0;$j < strlen($keyArr[$i]);$j++){
                $str = '';
                $tmpArr = str_split($keyArr[$i]);
                $tmpA = str_pad(base_convert($tmpArr[$j],16,2),4,0,STR_PAD_LEFT);
                $tmpB = str_pad(base_convert($initKeyArr[$j],16,2),4,0,STR_PAD_LEFT);
                for($k=0;$k

你可能感兴趣的:(后端,PHP)