#!/usr/bin/perl -w # Shift the alpha characters based on sum of coordinate values. use strict; use constant RANGE => 4; # Rotate an alpha character by the specified amount, preserving case. sub rot($$) { my ($c, $s) = @_; my $base = ($c =~ /[a-z]/) ? ord('a') : ($c =~ /[A-Z]/) ? ord('A') : undef; return defined($base) ? chr((ord($c) - $base + $s) % 26 + $base) : $c; } while( my $line = <> ) { my $x = 0; foreach my $c (map {chr $_} unpack "C*", $line) { print rot($c, ($x + $. * 2) % RANGE); $x++; } }