12-06-2009, 07:42 PM
huzzah x 2!
Code:
#!/usr/bin/perl
use strict;
use warnings;
sub usage {
print qq(
Usage:
$0 <text to encrypt> <# of letter to rotate [13 by default]>
eg... $0 lolencryptthis 5
);
exit;
}
sub rot_encrypt {
my ($text, $num_sub) = @_;
$text = "\U$text";
my %alphabet;
for(my $i = 0x41; $i <= 0x5A; $i++) {
my $sub = $i + $num_sub;
while($sub > 0x5A) {
$sub -= 0x1A;
}
$alphabet{chr($i)} = chr($sub);
}
my @text = split //, $text;
for(my $i = 0; $i < @text; $i++) {
$text[$i] = $alphabet{$text[$i]};
}
return join("",@text);
}
usage() if @ARGV != 2;
print rot_encrypt($ARGV[0], $ARGV[1]) . "\n";