php中的xor,在PHP中使用XOR加密/解密
我正在學習加密我有一個這樣的問題:
在我的XOR明文帶有一個密鑰后,我得到一個地址,“010e010c15061b4117030f54060e54040e0642181b17”,作為十六進制類型.如果我想從這個地下室得到明文,我該怎么辦PHP?
我嘗試將其轉換為字符串/ int,然后將其轉換為XOR(三個字母).但它不行.
這是代碼:
function xor_this($string) {
// Let's define our key here
$key = 'fpt';
// Our plaintext/ciphertext
$text = $string;
// Our output text
$outText = '';
// Iterate through each character
for($i=0; $i
{
for($j=0; $j
{
$outText .= ($text[$i] ^ $key[$j]);
//echo 'i=' . $i . ', ' . 'j=' . $j . ', ' . $outText{$i} . '
'; // For debugging
}
}
return $outText;
}
function strToHex($string)
{
$hex = '';
for ($i=0; $i < strlen($string); $i++)
{
$hex .= dechex(ord($string[$i]));
}
return $hex;
}
function hexToStr($hex)
{
$string = '';
for ($i=0; $i < strlen($hex)-1; $i+=2)
{
$string .= chr(hexdec($hex[$i].$hex[$i+1]));
}
return $string;
}
$a = "This is the test";
$b = xor_this($a);
echo xor_this($b), '-------------';
//
$c = strToHex($b);
$e = xor_this($c);
echo $e, '++++++++';
//
$d = hexToStr($c);
$f = xor_this($d);
echo $f, '=================';
這就是結果:
This is the test————-
PHP Notice: Uninitialized string offset: 29 in C:\
Users\Administrator\Desktop\test.php on line 210 PHP Stack trace: PHP
1. {main}() C:\Users\Administrator\Desktop\test.php:0 PHP 2. xor_this() C:\Users\Administrator\Desktop\test.php:239
Notice: Uninitialized string offset: 29 in
C:\Users\Administrator\Desktop\test.p hp on line 210
Call Stack:
0.0005 674280 1. {main}() C:\Users\Administrator\Desktop\test.php:0
0.0022 674848 2. xor_this() C:\Users\Administrator\Desktop\test.php:23 9
UBE^A?WEAVA?WEAV@?WEARAFWECWB++++++++
This is zs$fs?=================
為什么? “UBE ^A?WEAVA?WEAV@?WEARAFWECWB”是我在實際工作中遇到麻煩的結果.
總結
以上是生活随笔為你收集整理的php中的xor,在PHP中使用XOR加密/解密的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 汇编语言中xor指令_xor指令(ADC
- 下一篇: PHP用Socket上传图片