9

I found this Perl program:

''=~('(?{'.(']])@+}'^'-/@._]').'"'.('/<[*-_<+>?}{>]@}+@}]])@+}@<[*-_<+>?}{>]@^'^'`^=_^<]_[[]+[/,]_/]-/@._]/^=_^<]_[[]+[/,|').',$/})')

It prints "Obfuscated Perl to print obfuscated Perl"

I want to know how it actually prints this.

Sinan Ünür
  • 116,958
  • 15
  • 196
  • 339
Umair Ayub
  • 19,358
  • 14
  • 72
  • 146

1 Answers1

10

It is making good use of the bitwise string XOR operator ^.

']])@+}' ^ '-/@._]'

evaluates to print,

'/<[*-_<+>?}{>]@}+@}]])@+}@<[*-_<+>?}{>]@^' 
    ^ '`^=_^<]_[[]+[/,]_/]-/@._]/^=_^<]_[[]+[/,|'

evaluates to Obfuscated Perl to print obfuscated Perl" and the whole program reduces to

$ perl -MO=Deparse ...
'' =~ m[(?{print "Obfuscated Perl to print obfuscated Perl",$/})];
... syntax OK

Related: Acme::EyeDrops

mob
  • 117,087
  • 18
  • 149
  • 283
  • I still didnt get how it works :( it would be nice if you add detailed explanation for `']])@+}' ^ '-/@._]'` – Umair Ayub Jul 26 '16 at 18:31
  • Follow the link. The ordinal value of each character in the first string is XOR'd with the ordinal value of the corresponding character in the second string and converted back to a character. `ord("]")` is 93, `ord("-")` is 45, 93 xor 45 is 112. `chr(112)` is `p` – mob Jul 26 '16 at 18:34
  • 1
    Note that you need `use re 'eval';` with 5.24 and later. – Sinan Ünür Jul 26 '16 at 20:13