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
#2
Nice!!!!!!!!
Reply
#3
I picked this up, while checking out POE::Component::IRC Cookbook.
Code:
$rot13 =~ tr[a-zA-Z][n-za-mN-ZA-M];

Source: http://poe.perl.org/?POE_Cookbook/IRC_Bots
Reply
#4
(12-12-2009, 06:56 AM)0x80483fb Wrote: I picked this up, while checking out POE::Component::IRC Cookbook.
Code:
$rot13 =~ tr[a-zA-Z][n-za-mN-ZA-M];

Source: http://poe.perl.org/?POE_Cookbook/IRC_Bots

Yeah, but that way's no fun. And you can get rid of the capitals if you supply the 'i' modifier.
Reply


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: 1 Guest(s)