Fonality's obfuscation hiring filters

brian_d_foy on 2007-01-04T21:46:40

Fonality recently sponsored a Perl Golf competition with cash prizes as a way to draw attention to their open Perl positions. It's good to see the techies taking part in the human resources process and it sounds like it might be a good place to work.

Their junior Perl developer position says:

We're looking for eager, junior level Perl developers who are itching to work with world class Perl experts. If you can explain this:

s|(\d)|length(9 x $1)|eg;

We'd like to hear from you!


I figured that must be a trick question since it leaves $_ that same as when it started, although it did a lot of work to do that. It replicates the string 9 by the number it matched, takes the length of that, and uses it as the replacement. It's the same as not doing the substitution at all. It does have some side effects, but as a single line of code those really don't matter.

The senior Perl developer position isn't that much more challenging, although it is obfuscated:

s;(?:SEEKING)?;PERLqny~%|fsyx%~tz&;?$^X=~m.\w+$.
:DEVELOPERS;s"$&"Ktsf"i;s^.^chr ord($&)-5^eg;$\=$/;print||" ;) "


Using the techniques in my Mastering Perl chapter on "Cleaning up Perl" pretty much takes care of this. First, use B::Deparse:

$ perl -MO=Deparse snippet               
s/(?:SEEKING)?/PERLqny~%|fsyx%~tz&/ ? $^X =~ /\w+$/ : '???';
s/$&/Ktsf/i;
s/./chr ord($&) - 5;/eg;
$\ = $/;
'???' unless print $_;


It's basically a Caeser cipher that moves everything up five places. It populates $_ by replacing nothing with the starting string. It's interesting that it uses $^X, but that's really fragile. It assumes that the value is "perl", but I can also call this code with a perl binary with a different name:

$ /usr/local/bin/perl5.8.8 snippet
K@MGlity wants you!


Not only that, but I'd expect a senior Perl developer to insist on strict and warnings clean code:

$ perl -Mstrict -w snippet
Bareword "DEVELOPERS" not allowed while "strict subs" in use at snippet line 1.
Execution of snippet aborted due to compilation errors.


That's easy to fix up though and I kinda like my way to get "perl":

$_=(qq=SEEKING(=,q==);s===;s;(?:SENIOR)?;PERLqny~%|fsyx%~tz&;s?
`$^X -v`=~m/(?is)(?<=is\s\is.)\w+/:our $DEVELOPERS;s"$&"Ktsf"i;
s^.^chr ord($&)-5^egi;eval"format STDOUT=\n@*\n.";$^A=$_;write;


Stonehenge?

Ovid on 2007-01-04T21:53:34

Is Randal going to have to worry about replacing you now? :)

Re:Stonehenge?

brian_d_foy on 2007-01-05T00:03:05

I don't think I could get a sweeter deal than Stonehenge. I mean, when the Big Boss tries to make you go on cruises or work, life ain't bad.