Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
rot13 in perl
#1
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";
Reply


Messages In This Thread
rot13 in perl - by wat - 12-06-2009, 07:42 PM
RE: rot13 in perl - by Socrates - 12-08-2009, 09:43 PM
RE: rot13 in perl - by 0x80483fb - 12-12-2009, 06:56 AM
RE: rot13 in perl - by wat - 12-12-2009, 12:21 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Compile Error in Perl liveproject101 0 1,304 04-12-2013, 03:08 AM
Last Post: liveproject101
  [Perl] IRC Bot wchar_t 26 14,635 08-20-2012, 01:40 PM
Last Post: Trump
  Perl Ebook ven0m 2 1,834 05-04-2012, 08:14 AM
Last Post: ven0m
  Help with a program written in perl Rodman42866 1 1,689 03-09-2012, 03:16 AM
Last Post: AceInfinity
  HTML perl script AceInfinity 5 2,743 12-03-2011, 11:35 PM
Last Post: Closed Account

Forum Jump:


Users browsing this thread: 2 Guest(s)