Should you ever find yourself writing an obfu and want to make it pretty by formatting the code into a meaningful shape, it's really quite easy.

Create a format file made up of spaces (ASCII 32) and any other character to make your shape. When run, the code will be placed, character for character, in the format you designed. Spaces will remain spaces.

NOTE: This doesn't guarantee that the formatted code will run, but it will make it easier to fine-tune the formatted code.

# codeformat.pl # # CubicSpline # 2001/10/13 # # Purpose: Format perl source file in a particular shape. # # Run: perl codeformat.pl <perl source> <pattern file> use strict; use warnings; # SOURCE reads in the perl source code open SOURCE, $ARGV[0]; # PATTERN reads in the format text file open PATTERN, $ARGV[1]; # make a single string that contains entire source my $sourceline = join '', <SOURCE>; # strip out newlines and tabs and create character array, # reversed for popping. $sourceline =~ s/\n|\t//g; my @sourcechars = reverse split //,$sourceline; close SOURCE; my $output = ""; my $i; # read in pattern file line by line # for every non-space (ASCII 32) character # output the next char of the source string. while( <PATTERN> ) { chomp; my @patternchars = split //; for( $i = 0; $i <= $#patternchars;$i++) { $output .= $patternchars[$i] eq " " ? " " : pop @sourcechars; } $output .= "\n"; } close PATTERN; # print out the formatted source and any remaining # source that didn't fit into the pattern. print $output; if( scalar(@sourcechars) > 0 ) { print "\n\n",scalar(@sourcechars)," Remaining: \n\n", reverse @sour +cechars; }

In reply to Format your source code into arbitrary shapes by CubicSpline

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.