-1
它有比通过XOR加密数据更快的选择吗?PHP - 异或加密
private static function getBinary($string)
{
$output = '';
for($i = 0; $i < strlen($string); $i++)
{
$value = decbin(ord($string[$i]));
$binary = str_pad($value, 8, '0', STR_PAD_LEFT);
$output .= $binary;
}
return ($output);
}
private static function getCrypted($key, $value)
{
$output = '';
$key_index = 0;
$max = strlen($key);
for($i = 0; $i < strlen($value); $i++)
{
if($key_index >= $max){ $key_index = 0;}
$output .= ($key[$key_index] XOR $value[$i]) ? '1' : '0';
$key_index++;
}
return ($output);
}
对于小文本,它相对较快,但我需要加密大文本(3MB数据)。但是对于这个文件getCrypted()函数需要10-20秒,这是不可接受的。
$bin_text = self::getBinary($text); // cca 4 sec.
$bin_key = self::getBinary("12345"); // 0 sec.
return self::getCrypted($bin_key, $bin_text); // 11 sec+
那么,它有什么最快的方法吗?也许将文本转换为二进制文件而不使用0和1创建另一个字符串我不知道...谢谢你的回复。
'XOR'不是加密。 – axiac
@axiac http://www.tech-faq.com/xor-encryption.html –
任何你正在使用'^'操作符逐位完成而不是逐字节操作的原因......? – CBroe