#!/usr/bin/perl use strict; use warnings; #use diagnostics; my $letter_separation = 80; my $word = shift @ARGV; my $file = shift @ARGV; my $text; #Read in the contents of the file open FH, "<$file" or die "couldn't open $file for input"; { local $/; $text = ; } close FH; my $origtext = $text; my @words = split /[[:space:][:punct:]]/, $text; my @wordlist = grep {length $_ > 3} @words; {local $, = "!"; #print "\nCompiled this wordlist:", @wordlist,"\n"; } my %words; $words{$_}=1 foreach @wordlist; @wordlist = keys %words; $text =~ s/\n|\r/ /g; $text =~ s/[[:punct:][:space:]]//g; $text = lc($text); foreach my $sep ( 1..$letter_separation) { print "Searching for words with a letter separation of $sep\n"; my @letters = split //, $word; my @regexp = ("(.{0,20}", join(".{$sep}", @letters), ".{0,".($sep+20)."})"); my $regexp = join "", @regexp; #print $regexp, "\n\n"; while ( $text =~/$regexp/ig ) { my $block = highlight_block ( $1, $sep, $word ); foreach my $s ( 1..$sep) { my $i; my $charlength; foreach ( @wordlist ) { print "Word number: ", $i++, "\n"; $charlength += length($_); print "Total length sent: $charlength\n"; $block = highlight_block ( $block, $s, $_ ) ; } } print "---This is the original text----------------------------------------\n"; print find_orig($origtext, $block), "\n"; print "---Secret spooky message in text is in capitals---------------------\n\n"; print format_block($block, $sep), "\n"; } } sub format_block { my ( $block, $sep) = @_; return $block if $sep < 10; my $regexp = "(.{".($sep+1)."})"; $block =~ s/$regexp/$1\n/ig; $block =~ s/(.)/$1 /g; return $block; } sub highlight_block { my ($block, $sep, $word)=@_; #print "Before $word, $sep\n"; my @let = split //, $word; my $rep = ''; my $i=1; foreach my $l (@let) {$l = "(".$l.")(.{$sep})"; $rep.='\u$'.$i++.'$'.$i++.'';}; my $regexp2 = join "", @let; #print "Now scanning substring with $regexp2 and replacement target $rep\n"; my $ev = '$block =~ '."s/$regexp2/$rep/i"; eval $ev; print $block, "\n\n"; #print "block after\n"; return $block; } sub find_orig { my ($orig, $block)=@_; my @search = split //, $block; my $search = join("","(", join( "[[:space:][:punct:]]*", @search), ")"); $orig =~ /$search/gi; return $1;