Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi All

I am using Rot13 to jumble up a small script I was wondering if it is possible to use Rot13 on the source of a perl file without using the Filter::Util module? I dont have access to that module so if possible I'd like to use this method of jumbling the source without it.

I know the actual process or de-jumbling the rot13 method is so simple using a tr/// but how do i approach this if it is the source of that perl file?
Does anyone have any possible methods or suggestions?

Thanks

Replies are listed 'Best First'.
Re: Rot13 Source Jumbling
by belg4mit (Prior) on Dec 07, 2002 at 03:50 UTC
    Put the encoded source in __DATA__. read(DATA). Decode. eval. Work complete.

    --
    I'm not belgian but I play one on TV.

      This sounds what I need - I have never used this __DATA__ routine though, how do I approach that? Thanks!
Re: Rot13 Source Jumbling
by Zaxo (Archbishop) on Dec 07, 2002 at 04:10 UTC

    Study the source of Acme::Bleach. It is short and entertaining. It does something much like what you want.

    I've never needed source filters, which is what these things are called, but it's fun to try and think of a situation where they're useful.

    After Compline,
    Zaxo

      And also study the source of unbleach.pl to see how secure it is...... ;-)

      cheers

      tachyon

      s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

      Good grief. ActiveState has Acme::Bleach (and many other Acme:: modules) available via PPM.

Re: Rot13 Source Jumbling
by Ryszard (Priest) on Dec 07, 2002 at 07:36 UTC
    if you want to obfuscate your code, why not use the tried and true obfucation method and pack up your source code doing something like:
    my $retval = pack("H*", $perlscript);

    Then, to you execute it, unpack it then eval it.

    If you wanted to be really tricky you could create a cool serial number routine and embed it in your packed code...

      Hi Ryzard

      This sounds very interesting but Im unable to follow exactly how you mean, could you give an extremely short example?

      Thank you
Re: Rot13 Source Jumbling
by atcroft (Abbot) on Dec 07, 2002 at 03:44 UTC

    Basically you want something along the lines of:

    # # Warning: untried code # my $message = "Blah!"; my (%translation); my $alphabet = join('', (a..z)); # Cheezy, but does 2 passes, performing a uc() in between foreach (0..1) { my $startchar = ord(substr($alphabet, 0, 1)); foreach my $c (0..25) { $translation{chr($startchar + $_)} = substr($alphabet, $_ - 13, 1); } $alphabet = uc($alphabet); } # %translation now contains the value for each character # in ('a'..'z', 'A'..'Z') print("Old message: ", $message, "\n"); my @letters = split('', $message); my (@newmessage); while (@letters) { my $c = shift(@letters); $c = $translation{$c} if (defined($translation{$c})); push(@newmessage, $c); } $message = join('', @newmessage); print("New message: ", $message, "\n");

    Others may know a better way to implement it, and I look forward to seeing their postings. Hope it at least helps.

      Others may know a better way to implement it, and I look forward to seeing their postings

      Does it count if I use my Capt. Crunch magic decoder ring?  :-)

      $ echo '$0 & $0 &' > foo; chmod a+x foo; foo;
      Thank you very much - But would this code work for the script itself when executed? For example, the script would be all coded and I would need to run it:
      #!/usr/bin/perl use DESRAMBLER; cevag "Pbagrag-glcr: grkg/ugzy\a\a"; cevag "uryyb jbeyq";

      Thats a simple hello world script, but I have no idea how to descramble it at run time without using filter:util modules.