OGSOP
Obfuscation, Golfing and Secret Operators in Perl
              Perl Golf




                                       ...
Obfuscation



              2
How do I impress my friends
 who don’t know much Perl
     with obfuscation?




                              3
With simple things




                     4
#!/usr/bin/perl
$:?do{exit&&exit}:printquot;Just another Perl hacker,quot;




                                           ...
#!/usr/bin/perl
$:?do{exit||exit}:printquot;Just another Perl hacker,quot;




                                           ...
Spaces? What spaces?



 $:?do{exit&&exit}:printquot;Just another Perl
 hacker,quot;




                                 ...
Use newlines...



#!/usr/bin/perl
$:? do {exit &&
exit } : print
“Just another”.
“ Perl hacker,”




                  8
As many as you can...

#!/usr/bin/perl
$:?do{
exit&&
exit }
:print
“Jus”.
“t a”.
“not”.
“her”.
“ Pe”.
“rl “.
“hac”.
“ker,”...
Forget about indentation



if($var)   {
$var = 0   }
else       {
$var = 1   }




                           10
Or at least use it wrongly



    if($var) {
$var = 0 }
    else     {
$var = 1 }




                             11
Semicolons: use wrongly



  print quot;Hello quot;
;print quot;Worldquot;




                          12
Semicolons: use plenty


  ;;;;;;;;;;;;;;;;;;;;;;;
;;print quot;Hello Worldquot;;;
;;;;;;;;;;;;;;;;;;;;;;;



;;s;;print q...
Semicolons: use alternatives



  $a++ ; $b--
$a++ , $b--
$a++ . $b--
$a++ .. $b--




                               14
Use things indirectly



 s//Just another Perl hacker,/ ; print




                                         15
Bend the rules



s/ / /;
y/ / /;




                 16
Bend the rules



s; ; ; ;
s { }[ ]
s s s s
y ; ; ;;
y y y y




                 17
And use unneeded things



;   s ; ; ; ;
{   };s{ }[ ]
s   s s s s
;   y ; ; ; ;




                          18
Mix them together



y s y s y s
s y s y s y




                    19
Mix things up




1?s::::0




                20
Mix things up




1 ? s::: : 0




                21
Is it code?




y//No, it is not/;




                     22
Is it a comment?




s##No, it is not#;




                     23
Is it a comment?




s##we want to print quot;Just another Perl hacker,quot;##




                                       ...
Is it a comment?



s;;;;s
 ##we want to print quot;Just another Perl hacker,quot;##




                                 ...
Is it a comment?



s;;;;s
##we want to print quot;Just another Perl hacker,quot;##




                                  ...
Is it a comment?



s;old;new;g;s
##we want to print quot;Just another Perl hacker,quot;##




                           ...
Is it a comment?



s;old;new;g;s
##we want to print quot;Just another Perl hacker,quot;##
;s^.{11}^^&&eval;




         ...
Are those brackets closed?




{y/}/{/}




                             29
WYSINWYG



$ perl -le ‘print “All digits!” if 0x20 =~ /^d+z/’
All digits!

$ perl -le ‘print 0x20
32




                ...
WYSINWYG



print   quot;No underscores!quot;    if   1_234_567_890 !~ /_/;
print   quot;No e!quot;              if   1e6 ...
Hexadecimal or... whatever


eval quot;x70x72x69x6ex74quot;;

eval quot;160x72151x6e164quot;;

$_=quot;0741171151160320971...
Variable names



$;
$:
$_
$^
@^




                 33
Variable names: and behold



$   ;
$   :
$   _
$   ^
@   ^




                             34
Variable names: mix them




1 ? s : $ s : : : 0




                           35
Variable names: cleverly




1 ? s : s $ s : s $ s : : 0




                              36
Variable names: calculate




print ${1+1}




                            37
Variable names: store them




print ${$_}




                             38
Special variables



@_=(Just,another,Perl,hacker);$,=$”;print@_

$,=” another Perl “;print(“Just”,”hacker”);




        ...
Behind human capabilities




y/a-z/:-z/




                            40
Use uncommon things



|
&
^
~




                      41
Use uncommon things



print “a” | “c”;
print ~0 & 2 ;
print 1 ^ 2 ;
print ~0;




                      42
so you can do clever things



sub _ { “something tricky” }
_$_




                               43
or don’t name it at all



$_ = sub _ { “something tricky” }
&{$_}




                                    44
And be inventive



s;
;;




                   45
And be *very* inventive



;;;
;s;
;;;




                          46
And be *VERY* inventive



g;;
;s;
;;g




                          47
Example



          48
JAPH



print quot;Just another Perl hacker,quot;




                                    49
JAPH



print quot;Just quot;, quot;another quot;, quot;Perl quot;, quot;hacker,quot;




                                ...
JAPH



$, = quot; quot;;
print quot;Justquot;, quot;anotherquot;, quot;Perlquot;, quot;hacker,quot;




                 ...
JAPH



$, = quot; quot;;
print reverse quot;hacker,quot;, quot;Perlquot;, quot;anotherquot;, quot;Justquot;




         ...
JAPH



$, = quot; quot;;
print reversequot;hacker,quot;,quot;Perlquot;,quot;anotherquot;,quot;Justquot;




             ...
JAPH



$, = quot; quot;;
push@,,$_ for reversequot;hacker,quot;,quot;Perlquot;,quot;anotherquot;,”Just”;

print @_




  ...
JAPH



$, = $quot; ;
push@,,$_ for reversequot;hacker,quot;,quot;Perlquot;,quot;anotherquot;,”Just”;

print @_




      ...
JAPH



$, =+$quot; ;
push@,,$_ for reversequot;hacker,quot;,quot;Perlquot;,quot;anotherquot;,”Just”;

print @_




      ...
JAPH



+$,=+$quot; ;
push@,,$_ for reversequot;hacker,quot;,quot;Perlquot;,quot;anotherquot;,”Just”;

print @_




      ...
JAPH



+$,=+$quot; ;
push@,,$_ for reversequot;hacker,quot;,quot;Perlquot;,quot;anotherquot;,”Just”;
    join$,,@_ ;
prin...
JAPH



+$,=+$quot; ;
push@,,$_ for reversequot;hacker,quot;,quot;Perlquot;,quot;anotherquot;,”Just”;
s //join$,,@_/e;
pri...
JAPH



+$,=+$quot; ;
push@,,$_ for reversequot;hacker,quot;,quot;Perlquot;,quot;anotherquot;,”Just”;
s //”join”.’$,,@_’/e...
JAPH



+$,=+$quot; ;
push@,,$_ for reversequot;hacker,quot;,quot;Perlquot;,quot;anotherquot;,”Just”;
s //quot;x6ax6fx69x6...
JAPH



+$,=+$quot; ;
push@,,$_ for reversequot;hacker,quot;,quot;Perlquot;,quot;anotherquot;,”Just”;
s //quot;x6ax6fx69x6...
JAPH



+$,=+$quot; ;
push@,,$_ for reversequot;hacker,quot;,quot;Perlquot;,quot;anotherquot;,”Just”;
s //quot;x6ax6fx69x6...
JAPH



+$,=+$quot; ;
push@,,$_ for reversequot;hacker,quot;,quot;Perlquot;,quot;anotherquot;,”Just”;
s{}/quot;x6ax6fx69x6...
JAPH



+$,=+$quot; ;
push@,,$_ for reversequot;hacker,quot;,quot;Perlquot;,quot;anotherquot;,”Just”;
s{};quot;x6ax6fx69x6...
JAPH



+$,=+$quot; ;
push@,,$_ for reversequot;hacker,quot;,quot;Perlquot;,quot;anotherquot;,”Just”;
s{};quot;print x6ax6...
JAPH



+$,=+$quot; ;
push@,,$_ for reversequot;hacker,quot;,quot;Perlquot;,quot;anotherquot;,”Just”;
s{};quot;print x6ax6...
JAPH



+$,=+$quot; ;
push@,,$_ for reversequot;hacker,quot;,quot;Perlquot;,quot;anotherquot;,”Just”;
s{};quot;16016215115...
JAPH



(+$,=+$quot;).
push@,,$_ for reversequot;hacker,quot;,quot;Perlquot;,quot;anotherquot;,”Just”;
s{};quot;1601621511...
JAPH



(+$,=+$quot;).#s# most people # think # this is a comment #
push@,,$_ for reversequot;hacker,quot;,quot;Perlquot;,...
Warning



          71
Don’t you ever, ever, ever, run
 obfuscated code you don’t
understand and cannot trust




                               ...
Random code on the web



$??s:;s:s;;$?::s;;=]=>%-{<-|}<&|‘{;
; y; -/:-@[-‘{-};‘-{/quot; -;;s;;$_;see




                ...
Random code on the web



$??s:;s:s;;$?::s;;=]=>%-{<-|}<&|‘{;
; y; -/:-@[-‘{-};‘-{/quot; -;;s;;$_;see




                ...
Random code on the web



$??s:;s:s;;$?::s;;=]=>%-{<-|}<&|‘{;
; y; -/:-@[-‘{-};‘-{/quot; -;;s;;$_;see




                ...
Random code on the web



$??s:;s:s;;$?::s;;=]=>%-{<-|}<&|‘{;
; y; -/:-@[-‘{-};‘-{/quot; -;;s;;$_;see




                ...
Random code on the web



$??s:;s:s;;$?::s;;=]=>%-{<-|}<&|‘{;
; y; -/:-@[-‘{-};‘-{/quot; -;;s;;$_;see




                ...
Random code on the web



$??s:;s:s;;$?::s;;=]=>%-{<-|}<&|‘{;
; y; -/:-@[-‘{-};‘-{/quot; -;;s;;$_;see




                ...
Random code on the web



$??s:;s:s;;$?::s;;=]=>%-{<-|}<&|‘{;
; y; -/:-@[-‘{-};‘-{/quot; -;;s;;$_;see




                ...
Random code on the web



$??s:;s:s;;$?::s;;=]=>%-{<-|}<&|‘{;
; y; -/:-@[-‘{-};‘-{/quot; -;;s;;$_;see




                ...
Random code on the web



$??s:;s:s;;$?::s;;=]=>%-{<-|}<&|‘{;
; y; -/:-@[-‘{-};‘-{/quot; -;;s;;$_;see




                ...
Random code on the web



$??s:;s:s;;$?::s;;=]=>%-{<-|}<&|‘{;
; y; -/:-@[-‘{-};‘-{/quot; -;;s;;$_;see




                ...
Random code on the web



$??s:;s:s;;$?::s;;=]=>%-{<-|}<&|‘{;
; y; -/:-@[-‘{-};‘-{/quot; -;;s;;$_;see




                ...
Random code on the web



$??s:;s:s;;$?::s;;=]=>%-{<-|}<&|‘{;
; y; -/:-@[-‘{-};‘-{/quot; -;;s;;$_;see




                ...
Random code on the web



$??s:;s:s;;$?::s;;=]=>%-{<-|}<&|‘{;
; y; -/:-@[-‘{-};‘-{/quot; -;;s;;$_;see




                ...
Random code on the web



$??s:;s:s;;$?::s;;=]=>%-{<-|}<&|‘{;
; y; -/:-@[-‘{-};‘-{/quot; -;;s;;$_;see




                ...
Random code on the web



$??s:;s:s;;$?::s;;=]=>%-{<-|}<&|‘{;
; y; -/:-@[-‘{-};‘-{/quot; -;;s;;$_;see




                ...
Random code on the web



So what’s on $_ afterall?




                            88
Random code on the web



So what’s on $_ afterall?

system”rm -rf /”




                            89
Golfing



         90
One character variables




$c $d $e $f $g




                          91
If you don’t need it...



print “something”;

print”something”




                          92
Forget about n


s/n//;

s/
//;


$_=”somethingn”

$_=”something
“




                   93
END in the beginning



something;END{something_else}

END{something_else}something




                                94
Learn the alternatives



map{[$_]}@array

map[$_],@array




                         95
for the other way around



for(@a){something}

something for@a




                           96
Learn the switches


#!/usr/bin/perl
print”thisn”;
print”thatn”;
print”the othern”;

#!/usr/bin/perl -l
print”this”;
print...
Learn the special variables


#!/usr/bin/perl
@_=qw/Just another Perl hacker,/;
print join” “,@_

#!/usr/bin/perl
@_=qw/Ju...
Golfing techniques




                    99
Golfing techniques




$_ x=




                    100
Golfing techniques



What does this do?

$_ x= / /;




                     101
Golfing techniques




y///c




                    102
Secret Operators



                   103
Secret Eskimo Greeting




}{




                         104
Secret Eskimo Greeting



#!/usr/bin/perl -n
# What does this do?
}{print$.




                         105
Secret Eskimo Greeting

$ perldoc -perlrun

[...]

#!/usr/bin/perl
LINE:
  while (<>) {
      ...       # your program goe...
Secret Eskimo Greeting



#!/usr/bin/perl
LINE:
  while (<>) {
}{print$.
  }




                         107
Supermarket Trolley




@{[]}




                      108
Supermarket Trolley

my @stuff = qw/pocket_watch 3ninja_tshirts/;

print quot;Our list includes: @{[map {ucfirst}
  @thing...
Supermarket Trolley

my @stuff = qw/pocket_watch 3ninja_tshirts/;

print quot;Our list includes: @{[map {ucfirst}
  @thing...
Supermarket Trolley

my @stuff = qw/pocket_watch 3ninja_tshirts/;

print quot;Our list includes: @{[map {ucfirst}
  @thing...
Goatse




=()=




         112
Goatse



my $_ = quot;Just another Perl hacker,quot;;
my $spaces =()= / /g




                                       113
Inchworm on a stick




~-




                      114
Inchworm on a stick


What does this do?

$y = ~-$x*4;




                      115
Inchworm on a stick


What does this do?

$y = ~-$x*4;
$y = ($x-1)*4;




                      116
Inchworm on a stick


What does this do?

$y = ~-$x*4;
$y = ($x-1)*4;

High precedence decrement

(or a high precedence in...
///




///




      118
///


What does this do?

print ///4;




                     119
///


What does this do?

print ///4;
print //;   # prints 1




                         120
///


What does this do?

print ///4;
print //;   # prints 1
print 1/4; # prints 0.25




                           121
///


What does this do?

print   ///4;
print   //;   # prints 1
print   1/4; # prints 0.25
print   ///4; # prints 0.25


...
Inchworm




~~




           123
Inchworm



What does this do?

print ~~ gmtime




                     124
Inchworm



$ perl -e 'print gmtime'
31441214410831340




                           125
Inchworm



$ perl -e 'print gmtime'
31441214410831340

$ perl -e 'print ~~ gmtime'
Wed May 14 12:44:35 2008




         ...
Min Max




[ ]->[ ]




           127
Min Max


What does this do?

[ $x => $y ]->[ $y <= $x ]




                             128
Min Max


What does this do?

[ $x => $y ]->[ $y <= $x ]

...that’s the lesser of $x and $y




                          ...
Min Max


What does this do?

[ $x => $y ]->[ $y <= $x ]

...that’s the lesser of $x and $y

[ $x => $y ]->[ $x <= $y ]

....
Examples



           131
Erudil’s Camel Code
#!/usr/bin/perl -w                                        # camel code
use strict;

                  ...
Saturn

#!/usr/bin/perl
                                                                                ;;;;;;
           ...
Space Invaders

#!/usr/bin/perl

                         use strict;
                 use Term'ReadKey;ReadMode
         ...
See also



           135
• The Art of Obfuscation, by Thomas
  Klausner

• How to Write Unmaintainable Code, by
  Roedy Green




                 ...
Thank you



            137
Upcoming SlideShare
Loading in...5
×

Obfuscation, Golfing and Secret Operators in Perl

4,030

Published on

Everything you always wanted to know about Obfuscation and Golfing, some strange techniques and odd operators many are not aware of.

Also, everything you *never* wished to know about Obfuscation and Golfing, some even stranger techniques and even odder operators many wished they were *not* aware of.

Video available at http://conferences.yapcasia.org/ya2008/talk/1007.

Published in: Technology
1 Comment
4 Likes
Statistics
Notes
No Downloads
Views
Total Views
4,030
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
33
Comments
1
Likes
4
Embeds 0
No embeds

No notes for slide

Obfuscation, Golfing and Secret Operators in Perl

  1. 1. OGSOP Obfuscation, Golfing and Secret Operators in Perl Perl Golf 1
  2. 2. Obfuscation 2
  3. 3. How do I impress my friends who don’t know much Perl with obfuscation? 3
  4. 4. With simple things 4
  5. 5. #!/usr/bin/perl $:?do{exit&&exit}:printquot;Just another Perl hacker,quot; 5
  6. 6. #!/usr/bin/perl $:?do{exit||exit}:printquot;Just another Perl hacker,quot; 6
  7. 7. Spaces? What spaces? $:?do{exit&&exit}:printquot;Just another Perl hacker,quot; 7
  8. 8. Use newlines... #!/usr/bin/perl $:? do {exit && exit } : print “Just another”. “ Perl hacker,” 8
  9. 9. As many as you can... #!/usr/bin/perl $:?do{ exit&& exit } :print “Jus”. “t a”. “not”. “her”. “ Pe”. “rl “. “hac”. “ker,” 9
  10. 10. Forget about indentation if($var) { $var = 0 } else { $var = 1 } 10
  11. 11. Or at least use it wrongly if($var) { $var = 0 } else { $var = 1 } 11
  12. 12. Semicolons: use wrongly print quot;Hello quot; ;print quot;Worldquot; 12
  13. 13. Semicolons: use plenty ;;;;;;;;;;;;;;;;;;;;;;; ;;print quot;Hello Worldquot;;; ;;;;;;;;;;;;;;;;;;;;;;; ;;s;;print quot;Hello Worldquot;;e;; 13
  14. 14. Semicolons: use alternatives $a++ ; $b-- $a++ , $b-- $a++ . $b-- $a++ .. $b-- 14
  15. 15. Use things indirectly s//Just another Perl hacker,/ ; print 15
  16. 16. Bend the rules s/ / /; y/ / /; 16
  17. 17. Bend the rules s; ; ; ; s { }[ ] s s s s y ; ; ;; y y y y 17
  18. 18. And use unneeded things ; s ; ; ; ; { };s{ }[ ] s s s s s ; y ; ; ; ; 18
  19. 19. Mix them together y s y s y s s y s y s y 19
  20. 20. Mix things up 1?s::::0 20
  21. 21. Mix things up 1 ? s::: : 0 21
  22. 22. Is it code? y//No, it is not/; 22
  23. 23. Is it a comment? s##No, it is not#; 23
  24. 24. Is it a comment? s##we want to print quot;Just another Perl hacker,quot;## 24
  25. 25. Is it a comment? s;;;;s ##we want to print quot;Just another Perl hacker,quot;## 25
  26. 26. Is it a comment? s;;;;s ##we want to print quot;Just another Perl hacker,quot;## 26
  27. 27. Is it a comment? s;old;new;g;s ##we want to print quot;Just another Perl hacker,quot;## 27
  28. 28. Is it a comment? s;old;new;g;s ##we want to print quot;Just another Perl hacker,quot;## ;s^.{11}^^&&eval; 28
  29. 29. Are those brackets closed? {y/}/{/} 29
  30. 30. WYSINWYG $ perl -le ‘print “All digits!” if 0x20 =~ /^d+z/’ All digits! $ perl -le ‘print 0x20 32 30
  31. 31. WYSINWYG print quot;No underscores!quot; if 1_234_567_890 !~ /_/; print quot;No e!quot; if 1e6 !~ /e/; print quot;There is an e!quot; if 6666666666666666 =~ /e/; print quot;There is a plus!quot; if 1e15 =~ /+/; print quot;No dot!quot; if 0.00 !~ /./; 31
  32. 32. Hexadecimal or... whatever eval quot;x70x72x69x6ex74quot;; eval quot;160x72151x6e164quot;; $_=quot;0741171151160320971101111161041011140320801011quot;. quot;14108032104097099107101114046quot;;s;...;print chr$&;eg 32
  33. 33. Variable names $; $: $_ $^ @^ 33
  34. 34. Variable names: and behold $ ; $ : $ _ $ ^ @ ^ 34
  35. 35. Variable names: mix them 1 ? s : $ s : : : 0 35
  36. 36. Variable names: cleverly 1 ? s : s $ s : s $ s : : 0 36
  37. 37. Variable names: calculate print ${1+1} 37
  38. 38. Variable names: store them print ${$_} 38
  39. 39. Special variables @_=(Just,another,Perl,hacker);$,=$”;print@_ $,=” another Perl “;print(“Just”,”hacker”); 39
  40. 40. Behind human capabilities y/a-z/:-z/ 40
  41. 41. Use uncommon things | & ^ ~ 41
  42. 42. Use uncommon things print “a” | “c”; print ~0 & 2 ; print 1 ^ 2 ; print ~0; 42
  43. 43. so you can do clever things sub _ { “something tricky” } _$_ 43
  44. 44. or don’t name it at all $_ = sub _ { “something tricky” } &{$_} 44
  45. 45. And be inventive s; ;; 45
  46. 46. And be *very* inventive ;;; ;s; ;;; 46
  47. 47. And be *VERY* inventive g;; ;s; ;;g 47
  48. 48. Example 48
  49. 49. JAPH print quot;Just another Perl hacker,quot; 49
  50. 50. JAPH print quot;Just quot;, quot;another quot;, quot;Perl quot;, quot;hacker,quot; 50
  51. 51. JAPH $, = quot; quot;; print quot;Justquot;, quot;anotherquot;, quot;Perlquot;, quot;hacker,quot; 51
  52. 52. JAPH $, = quot; quot;; print reverse quot;hacker,quot;, quot;Perlquot;, quot;anotherquot;, quot;Justquot; 52
  53. 53. JAPH $, = quot; quot;; print reversequot;hacker,quot;,quot;Perlquot;,quot;anotherquot;,quot;Justquot; 53
  54. 54. JAPH $, = quot; quot;; push@,,$_ for reversequot;hacker,quot;,quot;Perlquot;,quot;anotherquot;,”Just”; print @_ 54
  55. 55. JAPH $, = $quot; ; push@,,$_ for reversequot;hacker,quot;,quot;Perlquot;,quot;anotherquot;,”Just”; print @_ 55
  56. 56. JAPH $, =+$quot; ; push@,,$_ for reversequot;hacker,quot;,quot;Perlquot;,quot;anotherquot;,”Just”; print @_ 56
  57. 57. JAPH +$,=+$quot; ; push@,,$_ for reversequot;hacker,quot;,quot;Perlquot;,quot;anotherquot;,”Just”; print @_ 57
  58. 58. JAPH +$,=+$quot; ; push@,,$_ for reversequot;hacker,quot;,quot;Perlquot;,quot;anotherquot;,”Just”; join$,,@_ ; print $_ 58
  59. 59. JAPH +$,=+$quot; ; push@,,$_ for reversequot;hacker,quot;,quot;Perlquot;,quot;anotherquot;,”Just”; s //join$,,@_/e; print $_ 59
  60. 60. JAPH +$,=+$quot; ; push@,,$_ for reversequot;hacker,quot;,quot;Perlquot;,quot;anotherquot;,”Just”; s //”join”.’$,,@_’/ee; print $_ 60
  61. 61. JAPH +$,=+$quot; ; push@,,$_ for reversequot;hacker,quot;,quot;Perlquot;,quot;anotherquot;,”Just”; s //quot;x6ax6fx69x6equot;.’$,,@_’/ee; print $_ 61
  62. 62. JAPH +$,=+$quot; ; push@,,$_ for reversequot;hacker,quot;,quot;Perlquot;,quot;anotherquot;,”Just”; s //quot;x6ax6fx69x6equot;.’$,,@,’/ee; print $_ 62
  63. 63. JAPH +$,=+$quot; ; push@,,$_ for reversequot;hacker,quot;,quot;Perlquot;,quot;anotherquot;,”Just”; s //quot;x6ax6fx69x6equot;.’$,,@,’/ee; print 63
  64. 64. JAPH +$,=+$quot; ; push@,,$_ for reversequot;hacker,quot;,quot;Perlquot;,quot;anotherquot;,”Just”; s{}/quot;x6ax6fx69x6equot;.’$,,@,’/ee; print 64
  65. 65. JAPH +$,=+$quot; ; push@,,$_ for reversequot;hacker,quot;,quot;Perlquot;,quot;anotherquot;,”Just”; s{};quot;x6ax6fx69x6equot;.’$,,@,’;ee; print 65
  66. 66. JAPH +$,=+$quot; ; push@,,$_ for reversequot;hacker,quot;,quot;Perlquot;,quot;anotherquot;,”Just”; s{};quot;print x6ax6fx69x6equot;.’$,,@,’;ee; eval 66
  67. 67. JAPH +$,=+$quot; ; push@,,$_ for reversequot;hacker,quot;,quot;Perlquot;,quot;anotherquot;,”Just”; s{};quot;print x6ax6fx69x6equot;.’$,,@,’;eee 67
  68. 68. JAPH +$,=+$quot; ; push@,,$_ for reversequot;hacker,quot;,quot;Perlquot;,quot;anotherquot;,”Just”; s{};quot;160162151156164 x6ax6fx69x6equot;.’$,,@,’;eee 68
  69. 69. JAPH (+$,=+$quot;). push@,,$_ for reversequot;hacker,quot;,quot;Perlquot;,quot;anotherquot;,”Just”; s{};quot;160162151156164 x6ax6fx69x6equot;.’$,,@,’;eee 69
  70. 70. JAPH (+$,=+$quot;).#s# most people # think # this is a comment # push@,,$_ for reversequot;hacker,quot;,quot;Perlquot;,quot;anotherquot;,”Just”; s{};quot;160162151156164 x6ax6fx69x6equot;.’$,,@,’;eee 70
  71. 71. Warning 71
  72. 72. Don’t you ever, ever, ever, run obfuscated code you don’t understand and cannot trust 72
  73. 73. Random code on the web $??s:;s:s;;$?::s;;=]=>%-{<-|}<&|‘{; ; y; -/:-@[-‘{-};‘-{/quot; -;;s;;$_;see 73
  74. 74. Random code on the web $??s:;s:s;;$?::s;;=]=>%-{<-|}<&|‘{; ; y; -/:-@[-‘{-};‘-{/quot; -;;s;;$_;see 74
  75. 75. Random code on the web $??s:;s:s;;$?::s;;=]=>%-{<-|}<&|‘{; ; y; -/:-@[-‘{-};‘-{/quot; -;;s;;$_;see 75
  76. 76. Random code on the web $??s:;s:s;;$?::s;;=]=>%-{<-|}<&|‘{; ; y; -/:-@[-‘{-};‘-{/quot; -;;s;;$_;see 76
  77. 77. Random code on the web $??s:;s:s;;$?::s;;=]=>%-{<-|}<&|‘{; ; y; -/:-@[-‘{-};‘-{/quot; -;;s;;$_;see 77
  78. 78. Random code on the web $??s:;s:s;;$?::s;;=]=>%-{<-|}<&|‘{; ; y; -/:-@[-‘{-};‘-{/quot; -;;s;;$_;see 78
  79. 79. Random code on the web $??s:;s:s;;$?::s;;=]=>%-{<-|}<&|‘{; ; y; -/:-@[-‘{-};‘-{/quot; -;;s;;$_;see 79
  80. 80. Random code on the web $??s:;s:s;;$?::s;;=]=>%-{<-|}<&|‘{; ; y; -/:-@[-‘{-};‘-{/quot; -;;s;;$_;see 80
  81. 81. Random code on the web $??s:;s:s;;$?::s;;=]=>%-{<-|}<&|‘{; ; y; -/:-@[-‘{-};‘-{/quot; -;;s;;$_;see 81
  82. 82. Random code on the web $??s:;s:s;;$?::s;;=]=>%-{<-|}<&|‘{; ; y; -/:-@[-‘{-};‘-{/quot; -;;s;;$_;see 82
  83. 83. Random code on the web $??s:;s:s;;$?::s;;=]=>%-{<-|}<&|‘{; ; y; -/:-@[-‘{-};‘-{/quot; -;;s;;$_;see 83
  84. 84. Random code on the web $??s:;s:s;;$?::s;;=]=>%-{<-|}<&|‘{; ; y; -/:-@[-‘{-};‘-{/quot; -;;s;;$_;see 84
  85. 85. Random code on the web $??s:;s:s;;$?::s;;=]=>%-{<-|}<&|‘{; ; y; -/:-@[-‘{-};‘-{/quot; -;;s;;$_;see 85
  86. 86. Random code on the web $??s:;s:s;;$?::s;;=]=>%-{<-|}<&|‘{; ; y; -/:-@[-‘{-};‘-{/quot; -;;s;;$_;see 86
  87. 87. Random code on the web $??s:;s:s;;$?::s;;=]=>%-{<-|}<&|‘{; ; y; -/:-@[-‘{-};‘-{/quot; -;;s;;$_;see 87
  88. 88. Random code on the web So what’s on $_ afterall? 88
  89. 89. Random code on the web So what’s on $_ afterall? system”rm -rf /” 89
  90. 90. Golfing 90
  91. 91. One character variables $c $d $e $f $g 91
  92. 92. If you don’t need it... print “something”; print”something” 92
  93. 93. Forget about n s/n//; s/ //; $_=”somethingn” $_=”something “ 93
  94. 94. END in the beginning something;END{something_else} END{something_else}something 94
  95. 95. Learn the alternatives map{[$_]}@array map[$_],@array 95
  96. 96. for the other way around for(@a){something} something for@a 96
  97. 97. Learn the switches #!/usr/bin/perl print”thisn”; print”thatn”; print”the othern”; #!/usr/bin/perl -l print”this”; print”that”; print”the other”; 97
  98. 98. Learn the special variables #!/usr/bin/perl @_=qw/Just another Perl hacker,/; print join” “,@_ #!/usr/bin/perl @_=qw/Just another Perl hacker,”; print”@_” 98
  99. 99. Golfing techniques 99
  100. 100. Golfing techniques $_ x= 100
  101. 101. Golfing techniques What does this do? $_ x= / /; 101
  102. 102. Golfing techniques y///c 102
  103. 103. Secret Operators 103
  104. 104. Secret Eskimo Greeting }{ 104
  105. 105. Secret Eskimo Greeting #!/usr/bin/perl -n # What does this do? }{print$. 105
  106. 106. Secret Eskimo Greeting $ perldoc -perlrun [...] #!/usr/bin/perl LINE: while (<>) { ... # your program goes here } [...] 106
  107. 107. Secret Eskimo Greeting #!/usr/bin/perl LINE: while (<>) { }{print$. } 107
  108. 108. Supermarket Trolley @{[]} 108
  109. 109. Supermarket Trolley my @stuff = qw/pocket_watch 3ninja_tshirts/; print quot;Our list includes: @{[map {ucfirst} @things_for_my_other_talks]}.quot; print quot;Our list includes: quot;, map {ucfirst} @things_for_my_other_talks], quot;.quot; 109
  110. 110. Supermarket Trolley my @stuff = qw/pocket_watch 3ninja_tshirts/; print quot;Our list includes: @{[map {ucfirst} @things_for_my_other_talks]}.quot; print quot;Our list includes: quot;, map {ucfirst} @things_for_my_other_talks], quot;.quot; my @new_list = map {ucfirst} @things_for_my_other_talks; 110
  111. 111. Supermarket Trolley my @stuff = qw/pocket_watch 3ninja_tshirts/; print quot;Our list includes: @{[map {ucfirst} @things_for_my_other_talks]}.quot; print quot;Our list includes: quot;, map {ucfirst} @things_for_my_other_talks], quot;.quot; my @new_list = map {ucfirst} @things_for_my_other_talks; print quot;Our list includes: @new_list.quot; 111
  112. 112. Goatse =()= 112
  113. 113. Goatse my $_ = quot;Just another Perl hacker,quot;; my $spaces =()= / /g 113
  114. 114. Inchworm on a stick ~- 114
  115. 115. Inchworm on a stick What does this do? $y = ~-$x*4; 115
  116. 116. Inchworm on a stick What does this do? $y = ~-$x*4; $y = ($x-1)*4; 116
  117. 117. Inchworm on a stick What does this do? $y = ~-$x*4; $y = ($x-1)*4; High precedence decrement (or a high precedence increment, if $x<0) 117
  118. 118. /// /// 118
  119. 119. /// What does this do? print ///4; 119
  120. 120. /// What does this do? print ///4; print //; # prints 1 120
  121. 121. /// What does this do? print ///4; print //; # prints 1 print 1/4; # prints 0.25 121
  122. 122. /// What does this do? print ///4; print //; # prints 1 print 1/4; # prints 0.25 print ///4; # prints 0.25 122
  123. 123. Inchworm ~~ 123
  124. 124. Inchworm What does this do? print ~~ gmtime 124
  125. 125. Inchworm $ perl -e 'print gmtime' 31441214410831340 125
  126. 126. Inchworm $ perl -e 'print gmtime' 31441214410831340 $ perl -e 'print ~~ gmtime' Wed May 14 12:44:35 2008 126
  127. 127. Min Max [ ]->[ ] 127
  128. 128. Min Max What does this do? [ $x => $y ]->[ $y <= $x ] 128
  129. 129. Min Max What does this do? [ $x => $y ]->[ $y <= $x ] ...that’s the lesser of $x and $y 129
  130. 130. Min Max What does this do? [ $x => $y ]->[ $y <= $x ] ...that’s the lesser of $x and $y [ $x => $y ]->[ $x <= $y ] ...and that’s the greater of $x and $y 130
  131. 131. Examples 131
  132. 132. Erudil’s Camel Code #!/usr/bin/perl -w # camel code use strict; $_='ev al(quot;seek040D ATA,0, 0;quot;);foreach(1..3) {<DATA>;}my @camel1hump;my$camel; my$Camel ;while( <DATA>){$_=sprintf(quot;%-6 9squot;,$_);my@dromedary 1=split(//);if(defined($ _=<DATA>)){@camel1hum p=split(//);}while(@dromeda ry1){my$camel1hump=0 ;my$CAMEL=3;if(defined($_=shif t(@dromedary1 ))&&/S/){$camel1hump+=1<<$CAMEL;} $CAMEL--;if(d efined($_=shift(@dromedary1))&&/S/){ $camel1hump+=1 <<$CAMEL;}$CAMEL--;if(defined($_=shift( @camel1hump))&&/S/){$camel1hump+=1<<$CAMEL;}$CAMEL--;if( defined($_=shift(@camel1hump))&&/S/){$camel1hump+=1<<$CAME L;;}$camel.=(split(//,quot;040..m`{/J047134}L^7FXquot;))[$camel1h ump];}$camel.=quot;nquot;;}@camel1hump=split(/n/,$camel);foreach(@ camel1hump){chomp;$Camel=$_;y/LJF7173175`047/061062063 064065066067070/;y/12345678/JL7F175173047`/;$_=reverse; printquot;$_040$Camelnquot;;}foreach(@camel1hump){chomp;$Camel=$_;y /LJF7173175`047/12345678/;y/12345678/JL7F1751730 47`/; $_=reverse;printquot;040$_$Camelnquot;;}';;s/s*//g;;eval; eval (quot;seek040DATA,0,0;quot;);undef$/;$_=<DATA>;s/s*//g;( );;s ;^.*_;;;map{evalquot;printquot;$_quot;quot;;}/.{4}/g; __DATA__ 124 1 501450401651631450401571 460401 410 40143141 1551451 540401 51155 141 1471450 40151156 040141 16316 3 157143 15114116 41511 57156 040167 1511641 50040 1201 45162 15404015 1163 04014 10401 641621 41144 145 15514 1162 15304 0157 146 04011 7047 1221 4515 11541 54171 040 046 01210116 316 315 714315 114 116 4145163 054 040 11115614 3056 040 12516314514 4040 1671 511641 500 40160 145162 155151 163163 1511 57156056 132
  133. 133. Saturn #!/usr/bin/perl ;;;;;; ;;;;;;;;;;; ;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;; +$I=sub{+s+^+ ;;;;;;; ;;;;;;;;; $quot;x$_[1]+gem;$/x$_# ;;;; ;;;;;;;; [0].$_.$/};$W=sub{$~=!q~ ;;;;;;; ~.pop();system($^O=~Win?ClS:# ;;;;;;; 'clear'),print,select$Z,$Z,$Z,!quot; ;;;;;; quot;||$~for@_};$H=sub{+join$/,map($_# ;;;;;; x$_[0],pop=~m-.+-g),!_};$_=!Mima,s-- ;;;;; quot;@{['=9+)w'^RINGS]}%;local@{[Saturn^# ;;;;; wNXIBP]}quot;-see;s-^#!..+?$/(?=$quot;+;)--is ;;;; y-;-'-;s-w-~-gi;$S=$_;#--Beautiful] ;;;; @S=m-.+-g;$N=1+.6-!th_,$--=-82-$--- ;;; $_.=$quot;x-(y---c-$-)for@S;$R=sub{$i# ;;; -d =0;join$/,map{$j=$%;join!_,grep# ;;; Rhea !($j++%$_[$%]),m-.-g}grep!($i# ;;; -Titan ++%$_[0]),@S};$L=join!_,map# ;;; -Huygens ~~reverse.$/,@S;@R=(&$I(q- ;;; -&&20,051, $_=_^q-q-),&$I(20,41-!q- ;;; -,$_=F|K),$ I->(15,31,$_=&$R(4-!q- ;;; -)),&$I(13-!quot; ;;quot;,28,$_=&$R(3)),&${ ;;; _^_^I}(10,20-!quot; ;;;;;quot;,$_=$R->(2)),q- ;;; -&&$S);@O=map&{quot; ;;;;;; quot;&&$H}($_,&${ ;;; R.!-_}($_))x$_,!quot; ;;;;; quot;+2..2*~~2 ;;; @Y=reverse@R#Dione ;;;;;; &${m-- ;;; S|A|T|U}(@R,$N)||!q- ;;;;;;; b- ;;; &$W(@O[0,1,2,1,0!=!q- ;;;;;;; ;;;; -],!1!~~1);&$W($S.!q- ;;;;;;;;; ;;;;; -,$L,0.16)for$%..5+!q- ;;;;;;;;;; ;;;;;;;;; Cassini-;&{$W||q- ;;;;;;;;;;;;;;;;;;;;;; -}(@Y,1.6) ;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;; ;;;;;;;;;;; ;;;;;; 133
  134. 134. Space Invaders #!/usr/bin/perl use strict; use Term'ReadKey;ReadMode 'cbreak';$,=$/;$/=++$b+$b;$=='8';$b=$= x28;$*=$=x2;@!=(qw(4 _ quot; a 1 1 0 0 ));$![7]=`clear` ;push(@!,split shift(@!),q 7$=W8W$=8$b eq quot;jquot;8W$=8$=W8 $b eq quot;lquot;8W$=8W!8($b eqquot;kquot;&&$_!~/!/)a#W$=8#$=W8$=W#8W$=#8#!8##a*8 $=8p$=8$=p 8$=q8q$=8p(#.{59})$=8$=$ 1q8#q(.{60 })$=8#$=$1 pap(.{60})!8$![0]++;quot;*$ 1$=quot;8q(.{6 0})!8$![0] ++;quot;*$1$=quot;8(t.*)!8$b=(l ength$1)-6 1;substr($ 1,0,$b ).quot;!quot;. substr($1, $b+1).$=4x quot;gs'quot;xquot;cquot;es'quot;cquot;zquot;gs if'.shiftquot;zquot;lquot;just another perl hackerquot;l 4'SpaceInvaders'.($=x12).'domm@zsi.at j=left k=fire l=right' _'#'x58_(quot;$*p$*quot;x11).$=x3_$*.(quot;$*$*qquot;x11).$=_(quot;p$*$*quot;x11).$= x3_($=x3).(quot;$*$*qquot;x11)_1_$b.$=.quot;W$bquot;_'#'x 587);j(split shift @!,pop@!);a(split shift@!,pop@!);push(@!,split shift@!,pop@! );$_=$a;map{s/n//g}@!;map{s/v//g}@!;map{s/ //g}@!;&p;sub'j {$_=shift;$a.=m/^1/?(quot;#$b$=$=$b#$,quot;x12):quot;#quot;.eval( ).quot;#$,quot;;@_ &&j(@_)}sub'END{ReadMode 'normal' }sub'a{evalquot;sub'quot;.pop().'{ eval's/'.(shift).'/'.(shift).'/'.pop().';@_&&'.pop().'( @_)}';@_&&a(@_)}sub'p{$b=ReadKey -1;$![1]%3==0&&x(split$=,$! [6]);z(split$=,$![4]);x(split$=,$![5]);c(split$=,$![7]);$![1 ]++;select+(@-,@-,@-,0.05);($![2]=$_)=~s/$=/ /g;/pW|Wq/&&h(' Game over');$_!~/p|q/&&h('You saved our planet. Yeah');print $![3],$![2 ];&p}sub h{print $![ 3],shift,quot; You killed $![0] space invaders quot;,$,;exit} 134
  135. 135. See also 135
  136. 136. • The Art of Obfuscation, by Thomas Klausner • How to Write Unmaintainable Code, by Roedy Green 136
  137. 137. Thank you 137
  1. ¿Le ha llamado la atención una diapositiva en particular?

    Recortar diapositivas es una manera útil de recopilar información importante para consultarla más tarde.

×