Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-25 10:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found