const
xorkey:array[0..7] of byte=($b2,$09,$aa,$55,$93,$6d,$84,$47); //字符串加密用
function dec(str:string):string;//字符解密函數
var
i,j:integer;
begin
result:='';
j:=0;
for i:=1 to length(str) div 2 do
begin
result:=result+char(strtoint('$'+copy(str,i*2-1,2)) xor xorkey[j]);
j:=(j+1) mod 8;
end;
end;
就上面几行代码,
求懂php的帮忙把这个函数翻译成php的,
我delphi加密,然后php解密,
我对php一点也不懂,但是懂调用。
------解决思路----------------------
$xorkey = array(0xb2,0x09,0xaa,0x55,0x93,0x6d,0x84,0x47);
echo $s = enc('edit2', $xorkey), php_eol;
echo dec($s, $xorkey);
function enc($str, $xorkey) { //:string;//字符加密函數 這是用的一個異或加密
$result = '';
$j = 0;
for($i=0; $i
$j = ($j+1) % 8;
}
return $result;
}
function dec($str, $xorkey){
$result = ;
for($i=0, $j=0; $i
$j = ++$j % 8;
}
return $result;
}
f76dc321a1
edit2
------解决思路----------------------
引用:能顺便把加密函数也翻译一下吗
function enc(str:string):string;//字符加密函數 這是用的一個異或加密
var
i,j:integer;
begin
result:='';
j:=0;
for i:=1 to length(str) do
begin
result:=result+inttohex(byte(str[i]) xor xorkey[j],2);
j:=(j+1) mod 8;
end;
end;
好测试密文
$xorkey = array(0xb2,0x09,0xaa,0x55,0x93,0x6d,0x84,0x47);
function dec($str){
global $xorkey;
$result = ;
$j = 0;
for ($i = 0; $i < strlen($str)/2; $i++)
{
$result = $result . chr(hexdec($str[$i*2] . $str[$i*2+1]) ^ $xorkey[$j]);
$j = ++$j % 8;
}
return $result;
}
function enc($str){
global $xorkey;
$result = ;
$j = 0;
for ($i = 0; $i < strlen($str); $i++)
{
$result = $result. dechex(ord($str[$i])^$xorkey[$j]);
$j = ++$j % 8;
}
return $result;
}
echo enc(edit2).\n;
echo dec(f76dc321a1);
