Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP XOR strings

Tags:

php

xor

I saw this code from an answer on PPCG:

echo BeeABBeeoBodBaBdOdPQBBgDQgDdp^"\n\n\t8b\n\n\t\nb&\nb b  \n%%nb%%%\n%\nQ";

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";

The output of those are:

Holy Hole In A Donut, Batman!

Can someone explain to me how the XOR of those two strings produce that line of output?

like image 906
rink.attendant.6 Avatar asked Feb 09 '23 07:02

rink.attendant.6


1 Answers

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;
  • ...

3v4l result

like image 126
Passerby Avatar answered Feb 11 '23 01:02

Passerby