#!/usr/bin/perl -w # Shift the alpha characters based on bayer matrix. use strict; # 4x4 Bayer dither matrix. my @bayer = ( [ 0, 8, 2, 10], [12, 4, 14, 6], [ 3, 11, 1, 9], [15, 7, 13, 5] ); # 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, $bayer[$. & 3][$x & 3]); $x++; } }