Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Obfu challenge! What is it?

by corenth (Monk)
on Sep 18, 2009 at 01:03 UTC ( #796009=obfuscated: print w/ replies, xml ) Need Help??

UPDATE 9/21/2009

Wow. this is a real reminder of how easy it is to fall prey to your own certainty. I tested my script on a couple of cases, and they turned out fine, so I assumed that all was well. I tried a new case and found that "something" was wrong. I fixed that something and was happy. I never bothered to test any other cases until later. OOPS! I have been running several cases after making my final adjustments. I believe that NOW the script solves all problems it's designed too. I AM crossing my fingers on this, but it looks like I've repaired all my bits. (pun absolutely intended- also a hint)

Well, not quite. There is one case that it does solve, & I don't know why that is... maybe someday I'll get it. As it is, I'm putting adjusted code in a less obfuscated manner bacause I'm a tad too lazy to worry about it...

Big UPDATE:

I left out a key peice of code in the obfuscation. The output was incorrect for the lack of that code. Now that it's in there, all problems of the sort that this code solves should be solved unless I hade any other errors in logic *sigh* Of course, if you have the non-corrected code, you might gain some insight from comparing the two versions.

I have three some challenges with this obfuscated code:

1. Can you figure out the purpose of this code?

2. What ways can the code be obfuscated further? I've never done this before, and haven't quite gotten the hang of it.

3. What metaphors do you think I've used? I use the term to refer to things like how I might visualise the data (tables, lists, objects) or how I perceive the problem (is it recursive, is A the function of B, is "brute force" used to solve a problem, or perhaps a genetic algorithm).

4. Better code? Keeping the metaphors you think I'm using, how can I optimize it to run faster?

5. Why is there a leading white space in the output- must be in there somewhere.. I've no idea..

Hints:

There are some optimizations that I have not used in order to keep with one "metaphor" that I'm using.

The problem I'm solving has been golfed before. This is DEFINITELY not a golf! I don't know about obfuscations.

The output needs to be formatted to make it recognizable to someone who knows this kind of problem. Also, while the problem's solved, the output values are not what's expected of solutions to this type of problem.. Update: Perhaps I should say that the output itself is slightly obfuscated. Correct output would by way too obvious.

As I said before " it looks like I've repaired all my bits" - pun and hint all in one!

I really don't know if this is going to be an easy task or an impossible one. If it's too difficult I will have to add hints. If I had to solve a puzzle like this, I'm not sure that I could.

Update: perl -v gives This is perl, v5.8.3 built for ppc-linux-thread-multi on my system. I doubt this will be an issue for anyone else.
#!/usr/bin/perl use integer; my $field ='8000401030005007001300000000002060805000000040204070000000 +00031002004000604070005'; $field =~s/[^\d]//g; $field =~s/(\d)/$1,/g; $field =~s/([1-9]),/(2**($1-1)).","/eg; my %h; for (1..9){$h{2**($_-1)}=$_}$h{0} = "-"; my $old = 'init'; my $new = ' 2nd init'; while ($old ne $new){ $new = ''; my $z = 0; for my $i (0..80){ my ($cell) = $field =~ /(?:\d+?,){$i}(\d+)/; my $b=($i/27)*27+3*(($i%9)/3); my $c =($i%9); my $r = ($i/9)*9; if ((!($cell))or($cell & ($cell - 1))){ $field =~ s/((?:\d+?,){$i})(\d+)/$1$z/; my $hb; map{$hb.=$_}map{/(\d+,\d+,\d+,)(?:\d+,){6}(\d+,\d+,\d+,)(? +:\d+,){6}(\d+,\d+,\d+,)/}$field=~/(?:\d+,){$b}(.*)/; my $hc; map{$hc.=$_}map{/(?:\d+,){$c}(\d+,)(?:\d+,){8}(\d+,)(?:\d+ +,){8}(\d+,)(?:\d+,){8}(\d+,)(?:\d+,){8}(\d+,)(?:\d+,){8}(\d+,)(?:\d+, +){8}(\d+,)(?:\d+,){8}(\d+,)(?:\d+,){8}(\d+,)/}$field=~/(.*)/; my $hr; map{$hr.=$_}map{/((?:\d+,){9})/}$field=~/(?:\d+,){$r}(.*)/ +; my $ha = $hr.$hc.$hb; my $nset = 511; map{($_ & ($_ - 1))?():($nset = ($nset & (511 ^ $_)))}$ha +=~/(\d+),/g; my $oset = 511; map{$oset = ($oset & (511 ^ $_))}$hr=~/(\d+),/g; ((!($oset & ($oset - 1)))and ($oset))?($nset = $oset):(); $oset = 511; map{$oset = ($oset & (511 ^ $_))}$hc=~/(\d+),/g; ((!($oset & ($oset - 1)))and ($oset))?($nset = $oset):(); $oset = 511; map{$oset = ($oset & (511 ^ $_))}$hb=~/(\d+),/g; ((!($oset & ($oset - 1)))and ($oset))?($nset = $oset):(); $field =~ s/((?:\d+?,){$i})(\d+)/$1$cell/; $cell = $nset; } $new .= "$cell,"; } $old = $field; $field = $new; } print "$field\n";
#!/usr/bin/perl use integer;use bigint;my $f = 815339036749889258964663919539108863582 +51535807693868444296494056897195949107537 + (2**266);$f =~s/(\d)/$1,/ +g;$f =~s/([1-9]),/(2**($1-1)).","/eg;my $scratch = ' ';my $hctarcs;my + $a = sub{'(\d+,\d+,\d+,)(?:\d+,){6}'};while ($scratch ne $hctarcs){$ +hctarcs = ' ';for (0..80){my ($fantabulous) = $f =~ /(?:\d+,){$_}(\d+ +)/;my $b=($_/27)*27+3*(($_%9)/3);my $c =($_%9);my $r = ($_/9)*9;if (( +$fantabulous < 1) or ($fantabulous & ($fantabulous - 1))){ $f =~ s/(( +?:\d+?,){$i})(\d+)/$1$z/;my $hb;map{$hb.=$_}map{/(\d+,\d+,\d+,)(?:\d+ +,){6}(\d+,\d+,\d+,)(?:\d+,){6}(\d+,\d+,\d+,)/}$f=~/(?:\d+,){$b}(.*)/; +my $hc;map{$hc.=$_}map{/(?:\d+,){$c}(\d+,)(?:\d+,){8}(\d+,)(?:\d+,){8 +}(\d+,)(?:\d+,){8}(\d+,)(?:\d+,){8}(\d+,)(?:\d+,){8}(\d+,)(?:\d+,){8} +(\d+,)(?:\d+,){8}(\d+,)(?:\d+,){8}(\d+,)/}$f=~/(.*)/;my $hr;map{$hr.= +$_}map{/((?:\d+,){9})/}$f=~/(?:\d+,){$r}(.*)/;my $ha = $hr.$hc.$hb;my + $nset = 511;map{(($_ & ($_ - 1)) and ($_))?():($nset = ($nset & (511 + ^ $_)))}$ha =~/(\d+),/g;my $mmmm_nice_yummi_scrumptious_bagels = 511 +;map{$mmmm_nice_yummi_scrumptious_bagels = ($mmmm_nice_yummi_scrumpti +ous_bagels & ($mmmm_nice_yummi_scrumptious_bagels - 1))}$hr=~/(\d+),/ +g;($mmmm_nice_yummi_scrumptious_bagels & ($mmmm_nice_yummi_scrumptiou +s_bagels - 1))?($nset = $mmmm_nice_yummi_scrumptious_bagels):();$mmmm +_nice_yummi_scrumptious_bagels = 511;map{$mmmm_nice_yummi_scrumptious +_bagels = ($mmmm_nice_yummi_scrumptious_bagels & ($mmmm_nice_yummi_sc +rumptious_bagels - 1))}$hc=~/(\d+),/g;($mmmm_nice_yummi_scrumptious_b +agels & ($mmmm_nice_yummi_scrumptious_bagels - 1))?($nset = $mmmm_nic +e_yummi_scrumptious_bagels):();$mmmm_nice_yummi_scrumptious_bagels = +511;map{$mmmm_nice_yummi_scrumptious_bagels = ($mmmm_nice_yummi_scrum +ptious_bagels & ($mmmm_nice_yummi_scrumptious_bagels - 1))}$hb=~/(\d+ +),/g;($mmmm_nice_yummi_scrumptious_bagels & ($mmmm_nice_yummi_scrumpt +ious_bagels - 1))?($nset = $mmmm_nice_yummi_scrumptious_bagels):();$f +antabulous = $nset;}$hctarcs .= "$fantabulous,";}$scratch = $f;$f = $ +hctarcs;}$f =~ s/(\d+),/$1/g;print "$f\n";
Good Luck!

Comment on Obfu challenge! What is it?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (9)
As of 2014-08-01 04:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (256 votes), past polls