Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

embedded gcc and awk

by Len (Friar)
on Mar 28, 2002 at 10:38 UTC ( [id://154920]=obfuscated: print w/replies, xml ) Need Help??

Feel free to break this code, which is using the power of embedded gcc and awk.
#!/usr/bin/perl $_='gcc 92 !$* % "awk in I$: ar& $:a"'; foreach(/(\S)/g){$;.=substr(unpack("B*" ,pack(n,unpack("c",$_))),-4);$;.="\n"if !(++$i%5);}$_=$;;y;0;\40;;y;1;#;;print;
Note: If you use Windows, you can use the windows compiler wcc instead of gcc.
If you don't have awk available, agk should work fine although I haven't test it myself.

Len ;-)

Replies are listed 'Best First'.
Re: embedded gcc and awk
by jmcnamara (Monsignor) on Mar 28, 2002 at 13:14 UTC

    I was disappointed to discover that you don't actually use gcc or awk. However, misdirection is a valid tool in obfuscation. ;-)

    Anyway here is a breakdown of the code. With reformatting it looks like this:

    $_='gcc 92 !$* % "awk in I$: ar& $:a"'; foreach (/(\S)/g) { $;.= substr(unpack("B*",pack(n,unpack("c",$_))),-4); $;.= "\n" if !(++$i%5); } $_=$;; y;0;\40;; y;1;#;; print;

    Substituting $str for $; and making some other changes:

    $_='gcc 92 !$* % "awk in I$: ar& $:a"'; foreach $char (/\S/g) { # Capturing parens not needed $str.= substr(unpack("B*",pack(n,unpack("c",$char))),-4); $str.= "\n" if !(++$i%5); } $_=$str; tr/0/\40/; tr/1/#/; print $_;

    Looking at the main substution in detail for the first character "g":

    $str.= substr(unpack("B*",pack(n,unpack("c",$char))),-4); unpack("c",$char) # is the same as ord $char # 103 pack(n, ... # packs 103 as a little-endian int unpack("B*", ... # Packs it as a binary string: 0000000001100111 substr(..., -4) # Get the last 4 chars: 0111

    After these substitutions $str looks like this:

    01110011001110010010 00010100101001010010 00010111101110011110 10010100101000010010 01100100101000010010

    The transliteration could be done in one pass:     tr/01/ #/; Applying the transliterations gives:

    ### ## ### # # # # # # # # # # #### ### #### # # # # # # # ## # # # # #

    I liked the joke about wcc and agk. :-) There is an example of a JAPH that does use an embedded awk (of sorts) here: JAAH

    --
    John.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2024-04-23 13:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found