Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Perl Python Partial Polyglot

by kschwab (Vicar)
on Jan 22, 2014 at 19:38 UTC ( [id://1071660]=obfuscated: print w/replies, xml ) Need Help??

Runs under perl and/or python and produces *almost* the same output...
0 and chr <<1; '''#' 1 use strict;use warnings; sub perl{ map{m&${\uc(q,m,)}&&&($,.=$_,)=~s,[^A-z0-6],,xg}@_;($_=$,) =~tr$A-Za-z0-9+,$ -_$;for(unpack("u",join('',map(chr(32+ length($_)*3/4).$_,m$(.{1,60})$gs)))){$.='$_'.'="';map {$..="\\$_"}unpack('(a3)*',$_.'012');$..='"';eval(${\$.}), s;\x50++\S{5}+;\u${\substr((caller(0e0))[0b11],-4) };;print}}${{}={<<'1<<1'=>1} #''' l=('137137151155160157162164137137''050047142141163145066064047051', '161056142066064144145143157144''145050143051', 'MTEyMTY1MTYzMTY0MDQwMTQxMTU2MTU3MTY0' 'MTUwMTQ1MTYyMDQwMTIwMTcxMTY0MTUwMTU3' 'MTU2MDQwMTUwMTQxMTQzMTUzMTQ1MTYyMDU0' ) def l1(l):[(yield'\\'+l[i:i+(2|1)])for i in xrange(0,len(l),(2|1))] i,I=lambda l:eval('"'+''.join(list(l1(l)))+'"'),lambda l:eval(i(l)) c,q=l[0o0+-0o1],I(l[0o1&0o2]);print(i(I(l[-(0o3^0o1)],))) ''' 1<<1 and 1; perl(split/\n/,(keys(%{${{}}))[0]) #'''
Note: edited 11/23/18 to fix error about keys() on a scalar.

Replies are listed 'Best First'.
Re: Perl Python Partial Polyglot
by eyepopslikeamosquito (Archbishop) on Nov 23, 2018 at 21:08 UTC

      From the "explanation" you linked above I was impressed by this:

      "o" from the second letter of bool: True.__class__.__name__1

      I thought one can extend this to cause error messages in $! (in Perl), e.g. "No such file or directory" and use single chars from them to try and form an obfuscated string. e.g. perl -e 'open(IN, "<", "");print @{[split(//,$!)]}[8,1,1,10,9,3,6];'

      Have I re-invented the wheel or is this my first obfuscated Perl signature?

      bw, bliako

        I guess ref() would be pretty similar.

        perl -e 'print @{[split //,ref(\$.)]}[-1,-2,0,1,-2,-3]'
      They almost all resort to using lambda though, which I ended up doing also. Not as fun/creative as obfuscated Perl.
Re: Perl Python Partial Polyglot
by eyepopslikeamosquito (Archbishop) on Nov 24, 2018 at 01:16 UTC
Re: Perl Python Partial Polyglot
by kschwab (Vicar) on Nov 23, 2018 at 13:42 UTC
    $ perl t1 Experimental keys on scalar is now forbidden at t1 line 25.
    Grrr, deprecation. Now I have to figure out how to fix it.

      Assuming the offending code looks something like this:

      my $hashref = { .... }; my $keysCount = keys $hashref;

      Then add a dereference:

      my $keysCount = keys ${ $hashref };

      Or just:

      my $keysCount = keys $$hashref;

      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
      In the absence of evidence, opinion is indistinguishable from prejudice. Suck that fhit
        Thanks...what ended up working was changing:
        perl(split/\n/,(keys(${{}))[0])
        to
        perl(split/\n/,(keys(%{${{}}))[0])

        Ahem, both of those snippets are non-working:

        $ perl -Mstrict -wE 'my $h = {foo=>"bar"}; my $c = keys ${$h};' Experimental keys on scalar is now forbidden at -e line 1. Type of arg 1 to keys must be hash or array (not scalar dereference) a +t -e line 1, near "};" Execution of -e aborted due to compilation errors.
        $ perl -Mstrict -wE 'my $h = {foo=>"bar"}; my $c = keys $$h;' Experimental keys on scalar is now forbidden at -e line 1. Type of arg 1 to keys must be hash or array (not scalar dereference) a +t -e line 1, near "$h;" Execution of -e aborted due to compilation errors.
        ... presumably you meant:
        $ perl -Mstrict -wE 'my $h = {foo=>"bar"}; my $c = keys %{$h};'
        $ perl -Mstrict -wE 'my $h = {foo=>"bar"}; my $c = keys %$h;'

        Aside: how odd that your post continues to garner upvotes (rep up three since I posted this); you don't suppose people vote based on the author's reputation without really reading the post, do you!?


        The way forward always starts with a minimal test.
Re: Perl Python Partial Polyglot
by boftx (Deacon) on Jan 23, 2014 at 14:28 UTC

    Have you considered becoming a member of Opus Dei?

    It helps to remember that the primary goal is to drain the swamp even when you are hip-deep in alligators.
      Heh. Trying to write obfuscated Python feels a bit like a cilice I suppose.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-04-20 16:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found