Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
How do I write messy (and sometimes entertaining code code?

The first thing you will probably notice is that this tutorial is a bit Obfuscated. I thought I would match the theme :) Often one may ask how to write highly obfuscated code in Perl. Its easy to write code. But can you write unreadable code? This is a simple tutorial guide, if you want to become a pro, practice your art.


1) Take advantage of Perl's end of line character ";". Use it to dirty up your code. For example, if you want to go for a certain shape you can use ";"'s to spruce it up:
my $cash_in; my $cash_ot ; my $cash_iz ; my $cash_zi ; my $cash_zo ; my $cash_is ; my $cash_if;
Languages that use ';' as a "end line" character are generally better for obfuscated because you can mush your code like so:
my $var="null\n";chomp($var);if ($var="null"){print "Good";}
You can also make an off beat pattern for your ';''s to add a bit of confusion, like so:
my $var="null\n" ;chomp($var) ;if ($var="null") {print "Good" ;}

2) Always break up your equal signs. Ie:

Try to do:

$myvar = "fdfdjsk";
instead of:
$myvar = "fdfdjsk";

3) Don't forget that, if you need better "shaping", always break up your strings with a new line character "\n";
4) Regular expressions make for messy code, and that is what we are going for. Use them in excess whenever possible.
5) Add comments. Sometimes adding odd comments here and there can help enhance the shaping of your code. An example of this is found in my work : "modern (perl) art" in the Obfuscated Code section of www.perlmonks.org. However,never comment in a way that would clarify your code.
6) Try to name your variables in a simplistic, yet inconherent way. "woodzy" has done a great job of this with his work called "Email sig. Old news. :/" on www.perlmonks.org. For example:
  instead of $payroll, try $p
  instead of $atom, try $a

7) Keep working. Practice enough and you WILL get good results. Someday you will even do lettering. You don't beleive that thats possible? Check out "Yet Another Perl Conference" by Erudil and you will see what I mean.
8) Keep your code as mathematical as possible. Never leave a simple expression alone, ie (4+4), but rather turn it into (((1*3)+1) + ((100*((1*2)+2)) /(10*10))). Doing this will make your code unreadable real soon.
9) Packing and unpacking will cause your code to be just a bit more unreadble. You will find many examples of this in www.perlmonks.org Obfuscated Code board.
10) Be sure to view some of the code found in Obfuscated Code section of www.perlmonks.org, its real helpfull on giving you some ideas on where to get started at making your code more un-readable. Please note that this is by no means a complete tutorial. I really hope that some other "perl obfuscator" will jump in and write a tutorial much better than this.
Thank you and have a good obfuscated night.

Edit 2001-04-03 by tye


In reply to Writing highly obfuscated code in Perl by marko

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others chilling in the Monastery: (7)
    As of 2014-07-12 01:21 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      When choosing user names for websites, I prefer to use:








      Results (238 votes), past polls