23
\$\begingroup\$

Classic code golf challenge. Write the most obscure Perl program to print "Just another Perl hacker". Here's the Wikipedia article on it. Bonus points if it fits in 3 lines / 70 characters each.

asked Jan 27, 2011 at 20:58
\$\endgroup\$
4
  • 2
    \$\begingroup\$ Obfuscated instead of obscure? \$\endgroup\$ Commented Jan 27, 2011 at 21:00
  • 18
    \$\begingroup\$ Code golf has to be about shortest code, not "most obscure". Shortest is objective. "Most obscure" is subjective. \$\endgroup\$ Commented Jan 27, 2011 at 21:00
  • 2
    \$\begingroup\$ @Chris: Wasn't this also about general programming puzzles? Ok, arguable whether obfuscation falls under that but as far as I understood it this wasn't a pure code golf site. \$\endgroup\$ Commented Jan 27, 2011 at 21:15
  • 1
    \$\begingroup\$ @Joey: It's not, but, the Stack Exchange platform is much more effective for objective questions, not ones "that the OP likes best". \$\endgroup\$ Commented Jan 27, 2011 at 21:18

5 Answers 5

34
\$\begingroup\$
eval eval '"'.
 ('['^"\+").(
 ('[')^ ')').('`'|')').
 ('`'|'.'). ('['^'/').('{'^'['
 ).'\\'.'"' .('`'^ '*').('['^'.').('['^
'(').('['^'/').('{'^ '[').('`'|'!').(('`')|
'.').('`'|'/').("\["^ '/').('`'|'(').('`'|'%'
 ).('['^')').(('{')^ '[').('{'^'+').('`'|'%').(
 '['^')').('`'| ',').('{'^'[').('`'|'(').('`'
 |'!').('`'|'#' ).('`'|'+').('`'|'%').('['^')').
 '\\'.'"'.("\!"^ '+').'"';$:='.'^'~';$~='@'|"\(";$^=
 ')'^'[';$/='`'| '.';,ドル='('^'}';$\='`'|'!';$:=')'^"\}";
 $~='*'|"\`";$^= '+'^'_';$/='&'|'@';,ドル='['&'~';$\=','^'|'
 ;$:='.'^'~';$~ ='@'|'(';$^=')'^'[';$/='`'|'.';,ドル='('^'}'
 ;$\='`'|'!';$: =')'^'}';$~='*'|'`';$^='+'^'_';$/='&'|'@';
 ,ドル='['&'~';$\=','^'|';$:='.'^'~';$~='@'|'(';$^=')'^'[';$/=
 '`'|'.';,ドル='('^'}';$\='`'|'!';$:=')'^'}';$~='*'|'`';$^='+'^
 '_';$/='&'|'@';,ドル='['&'~';$\=','^'|';$:='.'^'~';$~='@'|'('
 ;$^=')'^'[';$/='`'|'.';,ドル='('^'}';$\='`'|'!';$:=')'^'}';$~=
 '*'|'`';$^='+'^'_';$/='&'|'@';,ドル='['&'~';$\=','^'|';$:='.'^
 '~';$~='@'|'(';$^=')'^'[';$/='`'|'.';,ドル='('^'}';$\='`'|'!'
 ;$:=')'^'}';$~='*'|'`';$^='+'^'_';$/='&'|'@';,ドル="\["& '~'
 ;$\=','^'|';$:='.'^'~';$~='@'|'(';$^=')'^'[';$/='`' |((
 '.'));,ドル='('^'}';$\='`'|'!';$:=')'^'}';$~ ='*'|'`' ;$^
 ='+'^'_';$/='&'|'@';,ドル='['&'~';$\=','^ '|';$:= '.'
 ^'~'; $~='@'|'(';$^=')'^'[';$/="\`"| '.';,ドル= '('
 ^'}';$\='`'|'!';$:=')'^'}';$~ =('*')| '`'
 ;$^='+'^ '_';$/='&' |"\@"; ,ドル='[' &+
 '~';$\= ','^'|'; $:='.' ^"\~"; $~
 =('@')| "\(";$^= "\)"^ "\["; (
 ($/))= '`'|'.'; (,ドル) ='('
 ^"\}"; $\=('`')| '!'; ($:)
 =')'^ "\}";$~= '*'| '`';
 ($^)= '+'^'_' ;$/= '&'|
 '@'; ,ドル='[' &'~' ;$\=
 ','^ '|' ;$:= '.'^
 '~'; $~= '@' |((
 '(' )); $^= ')'
 ^(( '[' )); $/=
 '`' |(( '.' ))
 ;( (,ドル))= ((
 (( '(')) ))
 ^+ "\}";$\= ((
 '`' ))|+ "\!"; $:
 =(( ')'))^ '}'; $~=
 '*'| "\`";$^= '+' ^'_'
 ;($/)= ('&')|
 "\@";,ドル= '['&'~'
answered Oct 22, 2012 at 15:19
\$\endgroup\$
10
\$\begingroup\$
@H=@h=(176,138,140,17,87,54,126,182,217,223,136,130,136,117,73,52,154,
134,161,36,33,92,60,51);for(;$j<24;$j++){$x=0;for($k=0;$k<24;$k++){$x
+=@h[$k]<<($j*$k%24);$x%=241;}@H[$j]=$x;}print pack('c*',@H)

I'm not sure whether a newline at the end is required: if so, the addition of ."\n" still doesn't take me up to the limit of 3 lines * 70 chars/line.

If it weren't for encoding issues the initialisation could be much smaller and extracted with unpack, so I expect someone can improve on this. I'm thinking about making a more efficient version - this is O(n^2), and O(n lg n) decoding is possible.

answered Feb 8, 2011 at 23:50
\$\endgroup\$
1
  • \$\begingroup\$ +1 for <3 at the end of character value of your array! \$\endgroup\$ Commented Apr 28, 2011 at 19:53
5
\$\begingroup\$
use Time'HiRes"usleep";$|=@q=(a..z,' ');@w=('just another perl hacker'
=~/./g);while("@w"ne"@e"){$e[$_]eq$w[$_]or$e[$_]=$q[rand@q]for+0..$#w;
print"\r@e";usleep+1e5}

animated version :)

answered Apr 24, 2011 at 9:31
\$\endgroup\$
4
\$\begingroup\$

Less than 70 character on 3 lines:

$_=unpack("H21","9Ø
HvÂláμöÂ");s/(.)/" "x(hex1ドル<3).substr
"AHPJocehtunarslk",hex1,1ドル/eg;say

Care: It's ISO-8859-1 encoded.

perl -E '$_=unpack("H21","9Ø
HvÂláμöÂ");s/(.)/" "x(hex1ドル<3).substr
"AHPJocehtunarslk",hex1,1ドル/eg;say'
Just Another Perl Hacker 

More than 70 chars at all, but less than 100!

wc -clL <<< '$_=unpack("H21","9Ø
HvÂláμöÂ");s/(.)/" "x(hex1ドル<3).substr
"AHPJocehtunarslk",hex1,1ドル/eg;say'
 3 92 37

And a little obfuscated!

A little away?!

There is a <1'000 perl script with a full help and some features:

(It's ISO-8859-1 encoded too ;)

#!/usr/bin/perl -s
$;=$/;$_=q=sub'O{un=."144円e".q[f}sub'l{$#_==-1?leng].q[th:leng].'t'.q[h&a}sub'u{($.=
q;?02:;)=~y+0-@+a-q+;$. =~s/^/&a?"un].q[":""/mxe;$..=' "b';$..=do{$.].q[=~m+^u+?&a:1
}<<3;$..='","';$..=do{$.].q[=~m+^u+?"44円_":&a};eval $.."42円"}s].q[ub'a{pop}sub'b{$.=
"Hauri Félix, ";$v?do{$_=$.;y+?-^+_-~+;].q[s/\s.*/.ch/mgx;$_=do{0ドル=~m-j\w+-?$&.q.@.:
(q.w.x3).q,.,}.q qf-q].q[.$_;$..$_}:sub].q[str("lockpents ".$.,&a,1)}sub'p{pr]."in".
q<t do{$#_+1?&a."\n":do{/\n/?$_:$_.".\n"}}};sub'x{e>.pack("v",27000).q<t}sub't{sel>.
"ec".q<t O,&O,O,&a};$v&&{p 0ドル." 251円".(30*67)." ".b}&&x;$j&&do{$_="Îx126円§ÕIÕ220円o".
"2Õ";$_=>.q<u 12,1;s/.{4}/b ord u O,"$&",O/meg;tr+@-[+`-{+;s/./($.=$&)=~y.^-{.?-\\>.
q<\\.;$./xe;p;$c&&do{$c!=1&&do{$_=$c." ";p};fo>."reac".q<h$=(1..2*l){s/.//m;$_.=$&;p
"33円[A\r".$_;t.1}};x};$/=O;o>.chr(0x38*2).q-en$_,0ドル;$_=<$_>;$k&&p&&x||$p&&do{p;op-.q
len$p,$p;p<$p>;x};$h&&do{$_="Usal.q lge: ".0ドル." [ -v | -h | -j [-c[=string]] | -k |l
.q+ -p=file.pl ]";p;x};1+;eval||die+No.$;;

There are some features:

./japh.pl -h
Usage: ./japh.pl [ -v | -h | -j [-c[=string]] | -k | -p=file.pl ].

Where:

  • -v signature
  • -h help string
  • -j prompt Just another perl hacker.
  • -c animate the japh string or a submited string if any
  • -k dump the script himself
  • -p polute another script

So:

./japh.pl -j
Just another perl hacker.
./japh.pl -k | wc -lcL
 14 998 84
./japh.pl -p=$(which perldoc) >japhedPerldoc
chmod +x japhedPerldoc 
./japhedPerldoc perl | head
PERL(1) User Contributed Perl Documentation PERL(1)
NAME
 perl - The Perl 5 language interpreter
SYNOPSIS
 perl [ -sTtuUWX ] [ -hv ] [ -V[:configvar] ]
 [ -cw ] [ -d[t][:debugger] ] [ -D[number/list] ]
./japhedPerldoc -j -c
Just another perl hacker.

(The last string is animated:)

Trying to de-obfucate

There is a nice B::Deparse module available on CPAN:

perl -MO=Deparse japh.pl 
$; = $/;
$_ = qq[sub'O{undef}sub'l{\$#_==-1?length:length&a}sub'u{(\$.=\nq;?02:;)=~y+0-\@+a-q+;\$. =~s/^/&a?"un":""/mxe;\$..=' "b';\$..=do{\$.=~m+^u+?&a:1\n}<<3;\$..='","';\$..=do{\$.=~m+^u+?"\44円_":&a};eval\$.."\42円"}sub'a{pop}sub'b{\$.=\n"Hauri F351円lix, ";\$v?do{\$_=\$.;y+?-^+_-~+;s/\\s.*/.ch/mgx;\$_=do{\0ドル=~m-j\\w+-?\$&.q.\@.:\n(q.w.x3).q,.,}.q qf-q.\$_;\$..\$_}:substr("lockpents ".\$.,&a,1)}sub'p{print do{\$#_+1?&a."\\n":do{/\\n/?\$_:\$_.".\\n"}}};sub'x{e] . pack('v', 27000) . q[t}sub't{sel] . 'ec' . qq[t O,&O,O,&a};\$v&&{p \0ドル." \251円".(30*67)." ".b}&&x;\$j&&do{\$_="316円x271円\26円247円325円I325円\220円272円".\n"2325円";\$_=] . 'u 12,1;s/.{4}/b ord u O,"$&",O/meg;tr+@-[+`-{+;s/./($.=$&)=~y.^-{.?-\\' . '\\.;$./xe;p;$c&&do{$c!=1&&do{$_=$c." ";p};fo' . 'reac' . qq(h\$=(1..2*l){s/.//m;\$_.=\$&;p\n"\33円[A\\r".\$_;t.1}};x};\$/=O;o) . 'p' . 'en$_,0ドル;$_=<$_>;$k&&p&&x||$p&&do{p;op' . 'en$p,$p;p<$p>;x};$h&&do{$_="Usa' . 'ge: ".0ドル." [ -v | -h | -j [-c[=string]] | -k |' . ' -p=file.pl ]";p;x};1';
die 'No' . $; unless eval $_;
japh.pl syntax OK

Well, this is more readable, but...

Ok, there is a pack('v', 27000), what it mean:

perl -E "say pack('v', 27000)";
xi

Hmm. so we could try to simplify deparser's work:

perl -MO=Deparse <(sed -e <japh.pl 's/pack("v",27000)/"xi"/')
$; = $/;
$_ = qq(sub'O{undef}sub'l{\$#_==-1?length:length&a}sub'u{(\$.=\nq;?02:;)=~y+0-\@+a-q+;\$. =~s/^/&a?"un":""/mxe;\$..=' "b';\$..=do{\$.=~m+^u+?&a:1\n}<<3;\$..='","';\$..=do{\$.=~m+^u+?"\44円_":&a};eval \$.."\42円"}sub'a{pop}sub'b{\$.=\n"Hauri F351円lix, ";\$v?do{\$_=\$.;y+?-^+_-~+;s/\\s.*/.ch/mgx;\$_=do{\0ドル=~m-j\\w+-?\$&.q.\@.:\n(q.w.x3).q,.,}.q qf-q.\$_;\$..\$_}:substr("lockpents ".\$.,&a,1)}sub'p{print do{\$#_+1?&a."\\n":do{/\\n/?\$_:\$_.".\\n"}}};sub'x{exit}sub't{select O,&O,O,&a};\$v&&{p \0ドル." \251円".(30*67)." ".b}&&x;\$j&&do{\$_="316円x271円\26円247円325円I325円\220円272円".\n"2325円";\$_=u 12,1;s/.{4}/b ord u O,"\$&",O/meg;tr+\@-[+`-{+;s/./(\$.=\$&)=~y.^-{.?-\\\\.;\$./xe;p;\$c&&do{\$c!=1&&do{\$_=\$c." ";p};foreach\$=(1..2*l){s/.//m;\$_.=\$&;p\n"\33円[A\\r".\$_;t.1}};x};\$/=O;open\$_,\0ドル;\$_=<\$_>;\$k&&p&&x||\$p&&do{p;open\$p,\$p;p<\$p>;x};\$h&&do{\$_="Usage: ".\0ドル." [ -v | -h | -j [-c[=string]] | -k | -p=file.pl ]";p;x};1);
die 'No' . $; unless eval $_;
/dev/fd/63 syntax OK

Well, now it is clear that whole script is contained in qq(...) on line 2 and have to be submited to eval. We could now:

perl -MO=Deparse <(sed -e <japh.pl 's/pack("v",27000)/"xi"/') |
 sed -ne 's/$_ = \(qq(.*)\);/print 1円/p' |
 perl
/dev/fd/63 syntax OK
sub'O{undef}sub'l{$#_==-1?length:length&a}sub'u{($.=
q;?02:;)=~y+0-@+a-q+;$. =~s/^/&a?"un":""/mxe;$..=' "b';$..=do{$.=~m+^u+?&a:1
}<<3;$..='","';$..=do{$.=~m+^u+?"44円_":&a};eval $.."42円"}sub'a{pop}sub'b{$.=
"Hauri Félix, ";$v?do{$_=$.;y+?-^+_-~+;s/\s.*/.ch/mgx;$_=do{0ドル=~m-j\w+-?$&.q.@.:
(q.w.x3).q,.,}.q qf-q.$_;$..$_}:substr("lockpents ".$.,&a,1)}sub'p{print do{$#_+1?&a."\n":do{/\n/?$_:$_.".\n"}}};sub'x{exit}sub't{select O,&O,O,&a};$v&&{p 0ドル." 251円".(30*67)." ".b}&&x;$j&&do{$_="Îx126円§ÕIÕ220円o".
"2Õ";$_=u 12,1;s/.{4}/b ord u O,"$&",O/meg;tr+@-[+`-{+;s/./($.=$&)=~y.^-{.?-\\.;$./xe;p;$c&&do{$c!=1&&do{$_=$c." ";p};foreach$=(1..2*l){s/.//m;$_.=$&;p
"33円[A\r".$_;t.1}};x};$/=O;open$_,0ドル;$_=<$_>;$k&&p&&x||$p&&do{p;open$p,$p;p<$p>;x};$h&&do{$_="Usage: ".0ドル." [ -v | -h | -j [-c[=string]] | -k | -p=file.pl ]";p;x};1

In the hope deparser could better understand, now:

perl -MO=Deparse <(sed -e <japh.pl 's/pack("v",27000)/"xi"/') |
 sed -ne 's/$_ = \(qq(.*)\);/print 1円/p' |
 perl |
 perl -MO=Deparse
/dev/fd/63 syntax OK
sub O {
 undef;
}
sub l {
 $#_ == -1 ? length $_ : length &a;
}
sub u {
 ($. = '?02:') =~ tr/0-@/a-q/;
 $. =~ s/^/&a ? 'un' : '';/emx;
 $. .= ' "b';
 $. .= do {
 $. =~ /^u/ ? &a : 1
 } << 3;
 $. .= '","';
 $. .= do {
 $. =~ /^u/ ? '$_' : &a
 };
 eval $. . '"';
}
sub a {
 pop();
}
sub b {
 $. = "Hauri F351円lix, ";
 $v ? do {
 $_ = $.;
 tr/?-^/_-~/;
 s/\s.*/.ch/gmx;
 $_ = do {
 0ドル =~ /j\w+/ ? $& . '@' : 'w' x 3 . '.'
 } . 'f-' . $_;
 $. . $_
 } : substr('lockpents ' . $., &a, 1);
}
sub p {
 print do {
 $#_ + 1 ? &a . "\n" : do {
 /\n/ ? $_ : $_ . ".\n"
 }
 };
}
sub x {
 exit;
}
sub t {
 select O(), &O, O(), &a;
}
x if $v and {p(0ドル . " 251円" . 2010 . ' ' . b())};
if ($j) {
 $_ = "316円x271円\cV247円325円I325円220円2722円325円";
 $_ = u(12, 1);
 s/.{4}/b ord u(O(), "$&", O());/egm;
 tr/@-[/`-{/;
 s[.][($. = $&) =~ tr/^-{/?-\\/;
 $.;]ex;
 p ;
 if ($c) {
 if ($c != 1) {
 $_ = $c . ' ';
 p ;
 }
 foreach $= (1 .. 2 * l()) {
 s/.//m;
 $_ .= $&;
 p "\e[A\r" . $_;
 t 0.1;
 }
 }
 x ;
}
$/ = O();
open $_, 0ドル;
$_ = <$_>;
$p and do {
 p ;
 open $p, $p;
 p <$p>;
 x 
} unless $k and p and x ;
if ($h) {
 $_ = 'Usage: ' . 0ドル . ' [ -v | -h | -j [-c[=string]] | -k | -p=file.pl ]';
 p ;
 x ;
}
'???';
- syntax OK

Well! We got something near readable, now. Do this alway give same result?

perl -MO=Deparse <(sed -e <japh.pl 's/pack("v",27000)/"xi"/') |
 sed -ne 's/$_ = \(qq(.*)\);/print 1円/p' |
 perl |
 perl -MO=Deparse |
 perl -s /dev/stdin -j -c="That's all folks"
/dev/fd/63 syntax OK
- syntax OK
Just another perl hacker.
That's all folks .

(And the last line is animated:)

answered Oct 23, 2013 at 18:56
\$\endgroup\$
1
\$\begingroup\$
use strict;*1=*CORE'die,*!=*=,@=='hacker',s??'&1(@!,$/)'?ee;s;;%ENV=~m
,..,,ドル$&+10;e,@!=(chr.'ust',~~reverse('rehtona'),'Perl',$@);&1("@{=}")

It works with strictures enabled. Although it does not work on all machines/perls, because of CORE'die and ~~%ENV.

$ perl
use strict;*1=*CORE'die,*!=*=,@=='hacker',s??'&1(@!,$/)'?ee;s;;%ENV=~m
,..,,ドル$&+10;e,@!=(chr.'ust',~~reverse('rehtona'),'Perl',$@);&1("@{=}")
^Z
Just another Perl hacker
answered Oct 24, 2013 at 20:36
\$\endgroup\$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.