#!/usr/bin/perl -w
################################################################
# fritest.pl : Friedman's Test for a list of text chunks       #
#--------------------------------------------------------------#
# Compute scores for membership in a language                  #
#   English version, the ten most frequent letters are         #
#             ETOANIRSHD                                       #
#                                                              #
# List of texts from STDIN                                     #
# Output: a list of pairs (text, score) where                  #
#   text is the text chunk under test,                         #
#   score is the Friedman rate                                 #
#     = the relative number of the most frequent letters in    #
#     the text chunk.                                          #
#   Example: The (English) score of CAESAR is 5/6 = 0.833.     #
#--------------------------------------------------------------#
# Klaus Pommerening 2014-May-18                                #
#                                                              #
# This program is freeware. Use it as you like.                #
# Usual disclaimers apply.                                     #
################################################################

require "auxcrypt.pl";                   # Use &to26eng

while($a = <STDIN>) {
  $testtext = &to26eng($a);
  print $testtext;
  $rr = length($testtext);
  $nn = $testtext =~ s/[ETOANIRSHD]//g;  # English version
  if (!$nn) {$nn = 0;}
  print " ", $nn;
  $score = 0;
  if ($rr > 0) {$score = $nn/$rr;}
  printf (" %1.2f\n", $score);
  }
