Over a million developers have joined DZone.

Rot N

·

#!/usr/bin/perl -w
use strict;

my @file;
my @ascii;
my $val;
my $rot;
my $i;

$rot = 0;
if ($#ARGV >= 0) {
   if ($ARGV[0] >= 0) {
      $rot = $ARGV[0];
   } else {
      $rot = $ARGV[0] + 26;
   }
}

chop(@file = );

print "Rot:   $rot\n";
print "Lines: $#file\n";

print "-" x 80;

for ($i = 0; $i <= $#file; $i++) {

   @ascii = unpack("C*", $file[$i]);

   foreach $val (@ascii) {
      # uppercase
      $val = ($val + $rot - 65)%26 + 65   if ($val >= 65 && $val <= 90);
      # lowercase
      $val = ($val + $rot - 97)%26 + 97   if ($val >= 97 && $val <= 122);
   }

   print pack("C*", @ascii), "\n";
}

print "-" x 80, "\n";
Topics:

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}