#!/usr/bin/perl

# Set this to the URL of your Contact Script
my $URL = "http://GetDave.com/Contact.cgi";

##################################################
# Encryption..  Ooh, ahh!
##################################################
# You can pick one of the two methods below.  Just comment one of these out.

##################################################
# Method 1:  Obfuscated, not strong.  Shorter URLs
##################################################
my @c = ("a".."z"," ","A".."Z",1..9);
push(@c, qw(! @ # $ & * \( \) . + - _ )); push(@c,"\\");
my %c; for(my $i=0;$i<=$#c;$i++) {$c{$c[$i]}=$i;}

sub encrypt {
  my $i=0;
  join('',map {defined$c{$_}?$c[($c{$_}+(ord(substr($_[0],++$i%length$_[0],1))))%@c]:$_}
    split(//,reverse join("@",reverse split('\@',$_[1]))));
}

##################################################
# Method 2:  Strong, but longer URLs, requires packages
##################################################
#	#http://search.cpan.org/author/LDS/Crypt-CBC-2.08/CBC.pm
#use Crypt::CBC;
#	#http://search.cpan.org/author/DPARIS/Crypt-Blowfish-2.09/Blowfish.pm
#use MIME::Base64;
#sub encrypt {
#  my ($key,$str) = @_;
#  my $cipher = Crypt::CBC->new( {'key' => $key, 'cipher' => 'Crypt::Blowfish' })
#  my $ciphertext = encode_base64 $cipher->encrypt($str);
#  chomp($ciphertext);
#  $ciphertext;
#} 
#  

sub to_url($) {
  my ($str) = @_;
  $str =~ s/([^ a-zA-Z0-9\.])/"%".sprintf("%0.2x",ord($1))/eg;
  $str =~ s/ /+/g;
  $str;
}

die("\nUsage: $0 <key> <email> [name]\n\n") unless $#ARGV>0;
my ($key,$email) = (shift @ARGV, shift @ARGV);
print "$URL?t=".to_url encrypt($key,$email);
print "&n=".to_url(join(" ",@ARGV)) if @ARGV;
print "\n";

