答案 0 :(得分:4)
在字符串上使用xor:
my $x_hex = '08 F6';
my $y_hex = '4C 6E';
my $x = pack('(H2)*', split(' ', $x_hex)); # my $x = "\x08\xF6";
my $y = pack('(H2)*', split(' ', $y_hex)); # my $y = "\x4C\x6E";
my $z = $x ^ $y; # my $z = "\x44\x98";
my $z_hex = join(' ', unpack('(H2)*', $z)); # my $z_hex = "44 98";
在数字上使用xor:
my $x_hex = '08 F6';
my $y_hex = '4C 6E';
my @x = map { hex($_) } split(' ', $x_hex); # my @x = ( 0x08, 0xF6 );
my @y = map { hex($_) } split(' ', $y_hex); # my @y = ( 0x4C, 0x6E );
my @z = map { $x[$_] ^ $y[$_] } 0..$#x; # my @z = ( 0x44, 0x98 );
my $z_hex = join ' ', map { sprintf("%02X", $_) } @z; # my $z_hex = "44 98";