PHP异或字符串 [英] PHP XOR strings
本文介绍了PHP异或字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从 关于 PPCG 的答案 中看到了此代码:
I saw this code from an answer on PPCG:
echo BeeABBeeoBodBaBdOdPQBBgDQgDdp^"\n\n\t8b\n\n\t\nb&\nb b \n%%nb%%%\n%\nQ";
我知道 PHP 会将未定义的常量转换为字符串,所以等效的代码是:
I know PHP casts undefined constants into strings, so the equivalent code is:
echo 'BeeABBeeoBodBaBdOdPQBBgDQgDdp' ^ "\n\n\t8b\n\n\t\nb&\nb b \n%%nb%%%\n%\nQ";
这些的输出是:
Holy Hole In A Donut, Batman!
有人可以向我解释这两个字符串的异或是如何产生那一行输出的吗?
Can someone explain to me how the XOR of those two strings produce that line of output?
推荐答案
根据 这个官方示例,在字符串上使用 XOR
将对每个相应字符的 ASCII 值进行操作,因此在您的示例中:
According to this official example, using XOR
on strings will operate on ASCII values of each respectly character, so in your example:
B
^\n
= 66 ^ 10 = 72 =H
;e
^\n
= 101 ^ 10 = 111 =o
;e
^\t
= 101 ^ 9 = 108 =l
;- ...
B
^\n
= 66 ^ 10 = 72 =H
;e
^\n
= 101 ^ 10 = 111 =o
;e
^\t
= 101 ^ 9 = 108 =l
;- ...
这篇关于PHP异或字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文