Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Spiro Japh 2

by liverpole (Monsignor)
on Sep 03, 2005 at 15:30 UTC ( #488930=obfuscated: print w/ replies, xml ) Need Help??

After writing Spiro Japh, I wished I had thought to use color.  But when ikegami very kindly pointed out to me the existence of the excellent Win32::Console::ANSI module, I created Spiro Japh 2, which works colorfully in both Linux and Windows ...

(You will need to install the Win32::Console::ANSI module to run it under Windows)

#!/usr/bin/perl -w -w -w -w -w eval{ require Win32::Console::ANSI; };sub ::{printf @_ } sub sub{ rand 39/999} sub O123 {:: "" ."\e[%d" .";%dH%s" ,@_ ;}; sub l234 {O123 $|= 1 ,1, "\e[J"} while(1) { $c or do {::"\e[1" ."". "" .";%dm", 30+ rand 7 ; l234;$u=&sub ;$v = &sub ;$ c= 3999 ;$b=qw /19 9 1/[int rand 3 ]};O123 11*sin( $v* $c)+ 13,39*cos ($u*$c)+41, qw+J A P H+[$c%4] ;($a++%$b)or$c--;}

Edit by demerphq: restored code tags
Edit by holli: restored [, ] and &'s and fixed links to monastery format

Comment on Spiro Japh 2
Download Code
Re: Spiro Japh 2
by holli (Monsignor) on Sep 03, 2005 at 16:35 UTC
    wow!


    holli, /regexed monk/
Re: Spiro Japh 2
by sh1tn (Priest) on Sep 04, 2005 at 14:09 UTC
    excellent && of course ++


Re: Spiro Japh 2
by demerphq (Chancellor) on Sep 05, 2005 at 09:57 UTC

    A minor comment. We use <code></code> tags here for a reason. People use the site in different ways and like to have control over how code is rendered for them. When you post your code as you have you break this, which people find annoying. Its real easy to see your code as literal text if you use <code> tags even if it doesnt always render exactly as you might like for every users personal settings. But thats the point of personal settings, the user wants to choose and not simply accept what the author is willing to provide.

    Anyway, I quite enjoyed the posting. Thanks.

    ---
    $world=~s/war/peace/g

      I'm sorry, demerphq, I thought that I did use code tags, except for the text preceding the code.  The first time I submitted code (and thereafter as well), I used the same formatting tags that another monk had used, and perhaps that's why I didn't get it right -- in the future I'll just use '<code></code>' instead.  Anyway, thanks for fixing it!
Re: Spiro Japh 2
by udyog (Acolyte) on Sep 08, 2005 at 02:21 UTC

    Hello Brilliant!!

    Its nice one!! Great!!

    And, I am very interest to know the Obfuscation code. Is there any tutorial or any other help please.

    Thank You.

      Thank you -- but you are too kind!  I am really not very good at obfuscation compared to many of the others whose works have graced the Monastery before me.  I think my talents lie more with inventing something relatively new, and then making it hard to decipher.  The really inspired obfuscated code, though, takes much longer to unravel than anything I could create, and there are a number of them at Perlmonks.org which I have yet to come close to figuring out!

      I do have a couple of suggestions, though:

      1. For starters, always write code in an area that you are familiar with.  Just think this way:  "What would make for really cool-looking (and maybe very unexpected) program output?"  Then try to code to that.
      2. Create a program that you're pleased with first, and then try to obfuscate it afterwards.  If you have an obfuscation technique in mind at the outset, so much the better, but write code that's easy for you to comprehend before you make obfuscate it, otherwise you'll get lost in your own mess.
      3. If you're going for a certain "look", make sure that the number of characters in your code is very close to the number of characters in the "picture" which will be the final output.  Once you've got the program as short as you can make it, create an ascii-image using all '#' characters, and then, with your favorite editor, align your code to it as best you can.
      4. If you're trying "uncharted" techniques in obfuscation, make sure to try running your program after even the smallest edit, to make sure that it still works correctly!
      5. The more platforms your program runs on, the better (of course).
      6. Most importantly, study the obfuscated code that others have created.  If there are "spoilers" (explanations of how the code functions) make sure to read them carefully.  If not (or if you are up to the challenge), attempt to figure out for yourself which of the more mysterious Perl techniques are at work.  Learning these useful Perl idioms will provide you the inspiration you need, not only to create masterful obfuscations of your own, but to become a better craftsman of Perl yourself!

      Good luck!

        Spoiler...

        There is no much complicated obfuscation here, except by creating unnecessary subroutines and using weird names, such as "::" and "sub", and weird-looking names such as "O123" and "l234"... With only method and variable names modifications, I could use the code with use strict; and use warnings; without errors.

        The clean version of the code:

        #!/usr/bin/perl use warnings; use strict; $|= 1; # This is usefull and required only on win32 machines eval{require Win32::Console::ANSI;}; # number of JAPHs per graph my $counter; # define the parameters for the graph my ($u,$v); # a way to slow the counter decrease, see below my ($a,$b); while(1) { unless ($counter) { # choose a random color printf("\e[1;%dm", 30+rand(7)); # clear the screen printf("\e[%d;%dH%s",1,1,"\e[J"); $u = rand 39/999; $v = rand 39/999; $counter = 3999; $b=qw/19 9 1/[int rand 3]; }; # print J A P H, on the given position printf ( # the ansi code mask "\e[%d;%dH%s", # X 11*sin($v*$counter) + 13, # Y 39* cos($u*$counter) + 41, # one of the four letters qw/J A P H/[$counter%4] ); # here is how $a and $b are used. ($a++%$b) or $counter--; }
        daniel
Re: Spiro Japh 2
by QM (Vicar) on Sep 15, 2005 at 20:49 UTC
    Taking that a bit further...

    Why have warnings on if it's not warnings clean?

    Also, why not print the whole thing instead of the initials? You can probably do way better than this, but I'm just making the suggestion.

    #!/usr/bin/perl -- unless don't eval{ require Win32::Console::ANSI; };sub ::{printf @_ } sub sub{ rand 39/999} sub O123 {:: "" ."\e[%d" .";%dH%s" ,@_ ;}; sub l234 {O123 $|= 1 ,1, "\e[J"} while(1) { $c or do {::"\e[1" ."". "" .";%dm", 30+ rand 7 ; l234;$u=&sub ;$v = &sub ;$ c= 3999 ;$b=qw /19 9 1/[int rand 3 ]};O123 11*sin( $v* $c)+ 13,39*cos ($u*$c)+41, qw+J u s t A n o t h e r P e r l H a c k e r+[$c %21]; ($a++% $b) or $c--;}

    -QM
    --
    Quantum Mechanics: The dreams stuff is made of

      I'll be honest with you, I think it's better with with just the letters "JAPH" (or even "Japh"), as there's too much jibberish when you use all 4 words.  Additionally, the new picture looks worse, partly since it's -supposed- to be one of the self-generated patterns, and partly because it's just graphically not as good (eg. the dangling 'or' at the bottom looks out-of-place).

      But I'll agree with you on the warnings.  What happened was that after developing it under Windows, when I tried it the first time on Linux, I didn't actually see the warnings until long after I'd published it.

        ...the new picture looks worse, partly since it's -supposed- to be one of the self-generated patterns, and partly because it's just graphically not as good (eg. the dangling 'or' at the bottom looks out-of-place).
        So reformat it. Seriously, I just took a quick stab at it. I don't have the patience or skills, but I admire them in others.
        But I'll agree with you on the warnings. What happened was that after developing it under Windows, when I tried it the first time on Linux, I didn't actually see the warnings until long after I'd published it.
        I apologize in advance, but I don't run any program without running perl -c against it first, even for trivial edits. Many programs spew data (or runtime warnings) causing compiler warnings to scroll off the buffer, never to be seen again.

        -QM
        --
        Quantum Mechanics: The dreams stuff is made of

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: obfuscated [id://488930]
Approved by Tanktalus
Front-paged by grinder
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2014-09-23 10:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (219 votes), past polls