<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!perl

# obfuscate_js.pl
# By Jonathan Meyer &lt;http://stej.com&gt;
#
# This script is desinged to obfuscate javascript to the human reader but not
# to the javascript interperter.

use strict;
use Data::Dumper;

my $js_in = $ARGV[0];
my $js_out = $ARGV[1];

if( ! -e $js_in || -e $js_out )
{
  die "\nusage: obfuscate_js.pl &lt;in file&gt; &lt;out file&gt;\n";
}

open JS_IN, $js_in or die "\nError: $js_in: $!\n";

my $data = {};

while( &lt;JS_IN&gt; )
{
  my @line = split //;
  my $char = '';

  foreach $char( @line )
  {
  	if( $char !~ m/\n/ )
  	{
  	  push @{$data-&gt;{'in'}}, $char;
  	  $data-&gt;{'unique'}-&gt;{$char}++;
  	}
  }
}

close JS_IN;

open JS_OUT, "&gt;$js_out" or die "\nError: $js_in: $!\n";

my $char = '';
my $count = 0;

foreach $char( sort { $data-&gt;{'unique'}-&gt;{$b} &lt;=&gt; $data-&gt;{'unique'}-&gt;{$a} } keys %{$data-&gt;{'unique'}} )
{
  $data-&gt;{'map'}-&gt;{$char} = $count++;
  my $escape = '';

  if( $char eq "'" || $char eq "\\" )
  {
  	$escape = '\\';
  }

  $data-&gt;{'a'} .= $escape.$char;
}

foreach $char( @{$data-&gt;{'in'}} )
{
  if( defined $data-&gt;{'b'} )
  {
    $data-&gt;{'b'} .= ',';
  }

  $data-&gt;{'b'} .= $data-&gt;{'map'}-&gt;{$char};
}

# print JS_OUT Dumper( $data );

print JS_OUT "
var a='".$data-&gt;{'a'}."';
var b=[".$data-&gt;{'b'}."];
var q='';

for( x = 0; x &lt; b.length; x++ )
{
  q += a.charAt( b[x] );
}

eval( q );
";

close JS_OUT;

</pre></body></html>