Hold fire man - I am not asking how to do it, I am presenting a way it can be done.

Hiding the source code is not possible in perl - it can only be made less easy to read. However the following script can be used with interactive code to encrypt the functional bits.

#!/usr/local/bin/perl -w # An attempt at an end to those damn 'hide the source' nodes. # Usage: close-the-source.pl open_source.pl closed_source.pl # If you want to know what is going on go to: # http://perlmonks.com/index.pl?node_id=264840 use strict; use Crypt::Simple prompt => 'Please type the password now'; # Get the in and out off the command line. my $in_file = shift @ARGV; my $out_file = shift @ARGV; # Open the files. open IN, $in_file or die "Please specify file to scramble: $!"; open OUT, ">$out_file" or die "Please specify file to save to: $!"; # Grab the data and close the file. my @data = (); while (<IN>) { push @data, $_; } close IN; # Scramble the data my $scramble = encrypt( @data ); # Create closed_source.pl print OUT << "END"; #!/usr/local/bin/perl -w # If you want to know what is going on go to: # http://perlmonks.com/index.pl?node_id=264840 # Usage: 'perl $out_file | perl - args' use strict; use Crypt::Simple prompt => 'Please type the password now'; my \$scramble = '$scramble'; my \@clear = decrypt( \$scramble ); my \$code = join '', \@clear; print \$code; END # Be neat. close OUT; # Be rude. print "\n\nRight - run 'perl $out_file | perl - args' and stop pesteri +ng us.\n\n";

What it does is take the source code and encrypt it. Then it slaps the encrypted code into another perl script - whose only job is to decrypt the code and print it to STDOUT. This can be piped to perl and voila - hidden source execution of perl.

Take this test script as an example:

#!/usr/local/bin/perl -w print 'Look Dad - we can make millions now!', "\n\n"; print "Arguments are: ", join (', ',@ARGV), "\n\n";

Now run this at the prompt:

[evdb@machine]$ perl close-the-source.pl test.pl out.pl Please type the password now: secret Right - run 'perl out.pl | perl - args' and stop pestering us. [evdb@machine]$ perl out.pl | perl - 1 2 3 Please type the password now: secret Look Dad - we can make millions now! Arguments are: 1, 2, 3 [evdb@machine]$
It is not perfect but at least it should satisfy some of the requests for closing the source... Oh, and you should probably pick another encryption method if you are serious about this (and test it further - although it can handle html2ps just fine, and make the file smaller).

Update: Minor tweak to code (moved second #! line and added usage comment to closed source script).

--tidiness is the memory loss of environmental mnemonics


In reply to Code to hide the source for interactive scripts by EvdB

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.