Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

What's vec?

by iamcal (Friar)
on May 23, 2001 at 20:24 UTC ( [id://82609]=obfuscated: print w/replies, xml ) Need Help??

#!/usr/bin/perl -w use strict; $_="011291020310415102805081036150812103801030115081"; s/(..)/\\x$1/g;eval"\$_=\"$_\";";print,if($_=join'',map{ chr((vec($_,$?,2*$^F).vec($_,$|+1,4))+96)}split//)=~s;~; ;g;
dis-assemble at your leisure...

Replies are listed 'Best First'.
Re: What's vec?
by tachyon (Chancellor) on May 24, 2001 at 05:07 UTC
    vec EXPR, OFFSET, BITS The vec function provides a compact storage of lists of unsigned integers. These integers are packed as tightly as possible within an ordinary perl string. EXPR is treated as a bit string. OFFSET specifies the index of the particular element. BITS specifies how wide each element is in bits. Your JAPH does not run on my system, output: jtjt `jjt``j j`jj ```j`j cheers tachyon
      The question was rhetorical :p

      Do you have a dbcs? All my JAPH does is reverse the two bit-words of each character.

      Or perhaps your $?, $^F or $| don't default as mine do.

      try this version with hard coded constants:

      #!/usr/bin/perl -w use strict; $_="011291020310415102805081036150812103801030115081"; s/(..)/\\x$1/g;eval"\$_=\"$_\";";print,if($_=join'',map{ chr((vec($_,0,4).vec($_,1,4))+96)}split//)=~s;~; ;g;
Re: What's vec?
by tachyon (Chancellor) on May 24, 2001 at 16:20 UTC
    Different defaults it was, hard coded ran fine, but made the dissection less obfu :-( On my box $| is the problem, $| is 1, which flushes your JAPH too :-) print"\$?:$? \$^F:$^F \$|:$|\n"; $?:0 $^F:2 $|:1 So this runs $_="011291020310415102805081036150812103801030115081"; s/(..)/\\x$1/g;eval"\$_=\"$_\";";print,if($_=join'',map{ chr((vec($_,$?,2*$^F).vec($_,$|,4))+96)}split//)=~s;~; ;g; Disection follows (of the hard code) now that the use of: $?:0 $^F:2 $|:1 has been let out of the bag tachyon # this is what vec is # # another running dissection by tachyon # # code string $_="011291020310415102805081036150812103801030115081"; # this line grabs pairs from $_ and add hex escapes s/(..)/\\x$1/g; # this gives: # $_='\x01\x12\x91\x02\x03\x10\x41\x51\x02\x80\x50\x81\x03\x61\x50\x81 +\x21\x03\x80\x10\x30\x11\x50\x81'; # the function of this line is to convert the hex # escapes to their ascii representation due to the # interpolation that occurs to $_ eval"\$_=\"$_\";"; # the code below summarises these two steps # but it is now more obvious what is going on # uncomment it and this still runs so it must be right! # $_="011291020310415102805081036150812103801030115081"; # $_ =~ s/(..)/chr hex $1/eg; # I will rearrange this to make it easier to understand print, if($_=join'',map{chr((vec($_,0,4).vec($_,1,4))+96)}split//)=~s; +~; ;g; # first lets reset $_ using my shortened code $_="011291020310415102805081036150812103801030115081"; $_ =~ s/(..)/chr hex $1/eg; # split up our chars @ascii = split//,$_; #now we replace the map with this boring loop for (@ascii) { push @decode, chr((vec($_,0,4).vec($_,1,4))+96); } # join the decoded chars $_ = join'', @decode; # sub out the ~ chars s/~/ /g tr/~/ / s;~; ;g; #print it print "\n$_"; # so now all we need to understand is what vec does: # # vec EXPR, OFFSET, BITS # # The vec function provides a compact storage of lists of # unsigned integers. These integers are packed as tightly as # possible within an ordinary perl string. EXPR is treated as a # bit string. OFFSET specifies the index of the particular # element. BITS specifies how wide each element is in bits. # # So what happens is that for each eight bits we grab two # nybbles (4 bits) giving us 0-15 decimal after 'vec'ing. # we concat these together, run that through chr and # bob's your uncle

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2024-06-17 17:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.