I use something like this:
my $script_text = 'whatever'; # list var/sub names without %$@ # ensure vars can't pop up in other contexts - eg messages my @obsf = qw (var1 var2 sub1 sub2 ...); # remove comments - note I use "# ## to denote comment # to ensure only comments get removed $script_text =~ s/\s*# ##[^\n]+\n\s*/\n/gis; # remove extraneous CRs $script_text =~ s/;\s*\n\s*/;\n/gis; # and a few other things - html tags - tidy up $script_text =~ s/>\s+</></gis; # mess up indenting - make random $script_text =~ s/\t+/"\t" x (int(rand 6))/ges; # remove some crs $script_text =~ s/;\s+\}/; }/gis; $script_text =~ s/\}\s+elsif/} elsif/gis; $script_text =~ s/\{\s+/{ /gis; $script_text =~ s/\}\s+\}/} }/gis; $script_text =~ s/;\s+my/; my/gis; $script_text =~ s/if\s+\(/if \(/gis; # obfuscate array stuff majorly my $i=1; foreach (@obsf) { # create replacement my $replace = unpack ("B32", pack("N", $i)); $replace =~ s/^0+(?=\d)//; $replace =~ s/0/I/g; $replace =~ s/1/l/g; # replace in script $script_text =~ s/$_/$replace/gs; # move on... $i++; }

Makes it ugly to read, but anyone with time can unravel it.

Another option is using the Filter packages, but be prepared spending some time reading up on crypto - you have to write your own encryption, I believe. This is a lot more secure than plain obfuscation, but still readable by a determined hacker.

cLive ;-)


In reply to Re: Obfuscation of code... by cLive ;-)
in thread Obfuscation of code... by Stamp_Guy

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.