【发布时间】:2020-08-01 20:33:53
【问题描述】:
我有一个问题,为什么 xor p[i] 与 k 的结果是 00000238。应该是 00000110。
<?php
$Ciphertext = array();
$C = array();
$iv = 0;
$Kunci = "U";
$spsi= " ";
$Plaintext =$spsi."S";
$c0 = sprintf("%08d",
decbin($iv));
$key = dechex(ord($Kunci)) $k=sprintf("%08d",decbin(hexdec($key)));
$C[0]=$c0;
$P = array();
for($i =1;$i<strlen($Plaintext); $i++){
$P[$i] = dechex(ord($Plaintext[$i]));
$P[$i] = sprintf("%08d",decbin(hexdec($P[$i])));
$C[$i]=sprintf("%08d",(intval($P[$i])^intval($C[$i-1])));
$C[$i]=sprintf("%08d",(intval($C[$i])^intval($k)));
//$C[$i] = (bindec($C[$i]))<<1;
//if ($C[$i]>255)$C[$i]-=255;
//$C[$i] = sprintf("%08d", decbin($C[$i]));
//$Ciphertext[$i] = strtoupper(str_pad(dechex(bindec($C[$i])),2,"0",STR_PAD_LEFT));
}
echo "<br/>";
print_r($P);
echo "<br/>";
print_r($C);
echo "<br/>";
print_r($Ciphertext);
//echo implode(",", $P);
?>
然后输出:
数组 ( [1] => 01010011 ) 数组([0] => 00000000 [1] => 00000238) 数组 ( )
我想制作一个图片链接中的程序。 https://i.stack.imgur.com/mcBol.png
我想以这种方式获取这些值:
P1: 01010011
C0: 00000000
C1: XOR of P1 and C0
C1: 01010101
K: 01010101
C1: XOR of C1 and K
P2: 01100000
C1: 00001100
C2: XOR of P2 and C1
C2: 01111110
K: 01010101
C2: XOR of C2 and K
等等……
【问题讨论】:
-
评论不用于扩展讨论;这个对话是moved to chat。