#!/usr/bin/perl use strict; # name: shift-cipher # author: ap0calypse ( ap0calypse@agitatio.org ) # version: 0.1 ( 2008-02-08 ) # license: DO WHATEVER YOU WANT! # purpose: reads a sentence from STDIN an returns all # possible ciphered sentences. currently, all # input will be converted to lowercase letters. maybe # future versions will include support for uppercase # letters too. chomp (my $input = <>); # all input lowercase / without newline $input = lc $input; # the function that does the dirty work sub cipher_sentence { my ($hi_limit, $lo_limit) = (122, 96); # z, a-1 for calculating my ($sentence, $cipher_value) = (shift, shift); my @letters = split //, $sentence; my @sentence_ciphered; for my $letter (@letters) { my $num_letter = ord $letter; if ($num_letter != 32) { $num_letter += $cipher_value; if ($num_letter > $hi_limit) { my $shiftval = $num_letter - $hi_limit; $num_letter = $lo_limit + $shiftval; } push @sentence_ciphered, chr $num_letter; } else { push @sentence_ciphered, " "; } } push @sentence_ciphered, "\n"; return @sentence_ciphered; } # returning all possibilities for (1 .. 25) { print "shift by: $_ :\t", &cipher_sentence($input, $_); }