r.joseph has asked for the wisdom of the Perl Monks concerning the following question:

Hello. Although not at all new to perl, I am very new - not to mention very confused - to the whole obfuscation thing. I have been programming CGI in perl for a couple years now, and although it has allowed me time to learn perl very well, it does not afford many opprotunites to play with some of most interesting features in perl: the ones which I notice are used most often in JAPH's and such.

Here is my dillema - I really want to write a JAPH, yet I have no clue how to go about this. Is there any stratigies, tips, techniques, or magic tricks I should know about before I delve into the confusing world of obfuscation, or should I just pound on my keyboard, save and run it and see what happens?

Any tips on how to start obfuscating my life are greatly appreciated!
Thanks!
R.Joseph

Replies are listed 'Best First'.
Re: Lost in a sea of obfuscation...
by Adam (Vicar) on Dec 05, 2000 at 05:32 UTC
Re: Lost in a sea of obfuscation...
by cephas (Pilgrim) on Dec 05, 2000 at 05:31 UTC
    Well I'm not exactly an expert on obfuscation, the general principle would be to (ab)use the features of Perl as much as possible. Some of the more interesting ones I've seen come from abusing the delimeters for subsitute and match operators. japhy gives some good tips in japhy's Obfuscation Review. Also of course, you should remove uneeded whitespace and the like. Hope this gives you a starting point.

    cephas
Re: Lost in a sea of obfuscation...
by turnstep (Parson) on Dec 05, 2000 at 08:09 UTC

    If you look at the results of the latest Obfuscated Perl Contest, you'll notice that all the entrants were required to submit not only their code, but a "solution" file as well. With these, you can hear from the authors what each one does,and how it does it. My entry and a few other are on this site as well.

Re: Lost in a sea of obfuscation...
by zigster (Hermit) on Dec 05, 2000 at 15:01 UTC

    All the advice thus far given is good, however just to add my .04wassits. Before you look at the how, look at the what. Code obfiscation can be easily catagorised, there are various simple techniques. Judicious use of pack, (as has already been mentioned) using alternative substitution operators, using the ^? variables ;-) What is hard is comming up with the idea.. the what... If you look at other peoples japhs first you will (no matter how hard you try) reproduce what they have done. I would first of all sit down with a cup of java and try and work out what your japh is all about. To illustrate, a collegue of mine frankus wrote a cool japh a while ago based upon the rot algorithm. He stored a string and rotted it to produce the kick. Now the algorithm was obfiscated and he stuck some other nasties in there but the idea was simple. Get your idea first, then look at other japhs to see how to implement it in a -nasty- way.

    enjoy I look forward to seeing the result. --

    Zigster

      I love obfuscation. These obfuscations aren't Perl, I've yet to do Perl obfuscation. Obfuscation comes into it's own using, what other languages calumny as "side-effects" and Perl folk know as 'features'.

      I made a confusing method to produce a Just Another ... for each language. I found the suitability of each language to the job was telling and I tried to have fun with the language's idiom along the way.

      The method is pretty simple:

      • Use a=a^b, b=a^b, a=a^b to juxtapose two variables; I perform a=a^b, b=a^b to generate an XOR'd value.
      • Use a rot5 * to scramble the key to produce the string
      • By XORing each element of the two above you get the phrase. (I chose job titles to reflect my view of the attitude prevailent in the practicioners of each language.)

      When I wrote these, a Java / Perl war was ongoing at work. Not wanting to pick sides (why reduce the chance of a good scrap? :). I used Mutt's mailhooks, to "tune my subtle song". For posterity here are my sig lines (Please don't -- me for referring to other languages, I found the conciseness rang out from these. Yeah I know the Java is a tad long winded but.....)

      # Frank Booth, AHEM DIGITAL (www.ahem.com) tel:(XXX) XXXX XXXX $_='Ozxy%fstymjw%';s:.:chr((ord$&)-5):geo;split//;print$_,map{ $_[$_]^chr((26,16,1,24,0,9,15,12,31,13,23,92,42)[$_])}(0..$#_) /*Frank Booth, AHEM DIGITAL (www.ahem.com) tel: +XX (XXX) XXXX XXXX */ main(){char l[0x1b]={"Ozxy%fstymjw%"};int i=0,I[13]={9,85,3,6,79,6,28, 14,25,5,0,0,14};for(;13-i;l[13+i]=(l[i]-=5)^I[i++]);printf("%s\n",l);} //Frank Booth, AHEM DIGITAL (www.ahem.com) tel: +XX (XXX) XXXX XXXX import java.*;public class S{String a=new String(s("Ozxy%fstymjw%O" ));int[] b={43,3,18,84,68,4,24,10,24,7,21,23,82,100}; public static void main(String[]S){S s=new S();System.out.print(s);}public static String s(String b){StringBuffer w=new StringBuffer(b);for(int i=0;i <0xe; w.setCharAt(i,(char)(w.charAt(i++)-5)));return w.toString();} public String s(){StringBuffer w=new StringBuffer(a);for(int i=0;i< w.length();w.setCharAt(i,(char)(b[i]^(int)w.charAt(i++))));return w .toString();}public String toString(){return a+s()+"\n";}}/* :-) */ <!-- Frank Booth, AHEM DIGITAL (www.ahem.com) tel:(XXX) XXXX XXXX> <html><body bgcolor=#666666 text=#CC9900>&#074;u&#115;&#116;&nbsp; &#097;&#110;&#111;&#116;&#104;&#101;&#114;&#153;&nbsp;<b>&#072;<!- ->&#084;&#077;&#076;&nbsp;</b>w&#114;&#105;te&#114; </body></html>

      (The company name has been changed to protect the innocent, namely me ;0).

      * Okay it's not a true rot routine, but I think this is:    perl -pe's/([a-m])|[n-z]/chr(($1?13:-13)+ord$&)/ogie'

      --
      
      Brother Frankus.
        /([a-m])|[n-z]/chr(($1?13:-13)+ord$&)/ogie

        I know this handles capitals, but isn't it a slight overcomplication of what is really: tr/a-z/n-za-m/

        Or is that part of the obfuscation? Sorry if I've missed the point.

        --
        Brother Marvell