#!/usr/bin/perl -w
################################################################
# probwd.pl : Test probable word                               #
#--------------------------------------------------------------#
# Transliteration of special characters according to English   #
#   rules                                                      #
# For special characters of other languages use preptext.pl    #
#   first.                                                     #
#--------------------------------------------------------------#
# Klaus Pommerening 2013-December-23                           #
#                                                              #
# This program is freeware. Use it as you like.                #
# Usual disclaimers apply.                                     #
################################################################

require "auxcrypt.pl";     # Use standard alphabet
                           #   as global variables $alphabet,
                           #   @alphabet, and %sa.
                           # Use procedures &to26,
                           #   &gettext, &makeperm, &puttext.

$probw = &to26($ARGV[0]);   # Get probable word from command line.
$lpw = length($probw);
@pwlist = split(//,$probw);    # split as list of characters.

$ciphertext = &gettext;             # Get ciphertext from standard
                                    #   input,
$lct = length($ciphertext);
@ctlist = split(//,$ciphertext);    # split as list of characters.

for ($pos = 0; $pos + $lpw < $lct; $pos++) {
  $testtext = "";
  for ($i = 0; $i < $lpw; $i++) {
    $k = $sa{$ctlist[$pos + $i]};
    $l = $sa{$pwlist[$i]};
    $m = $k - $l; if ($m < 0) {$m +=26;}
    $testtext .= $alphabet[$m];                  # Append result to ciphertext
    }
  print $pos, ": ", $testtext, "\n";
  }
