You are viewing a single comment's thread.

view the rest of the comments →

23235460? ago

I wrote some code to help with this (Digits here). I'll copy it below. I should really put it on a site to make it easier but then of course it'd be easier to attack. This way, you can run it locally. Run it like:

perl find-word.pl maeve fahey kennedy townsend gideon mckean

and it'll give this output:

Searching ["Our national identity is being remade in real time. What had once seemed a bitter and divided society now seems more like a nation of people finding creative ways to show up for one another." - @nytdavidbrooks]

Searching for [maeve]: found.

Searching for [fahey]: found.

Searching for [kennedy]: found.

Searching for [townsend]: found.

Searching for [gideon]: found.

Searching for [mckean]: found.

Returning [1] ALL FOUND

I put Comey's tweet in as the default text; you can change the text to search by adding "--text='the text to search'".

Note that I didn't code anything to do with the grille cipher; I'm just helping the search for word(s) within a larger text, each word of which might be broken up.

The search matches regardless of whether the letter is capitalized or not.

Code is below, in a "code" block so hopefully it's copy/paste-able (verified during preview; this should work).

#!/usr/bin/perl
=head1 find-word.pl

This script will search text for specified words; the words might be broken up.

Author: unknown :)
Date: 2020-04-04 Sat 11:27

=cut


=head2 ALWAYS USE STRICT AND WARNINGS
=cut
use strict;
use warnings;


=head2 MODULES USED FROM CPAN
=cut
use Getopt::Long;


=head2 MODULES WRITTEN IN-HOUSE
=cut


=head2 VARIABLE DECLARATIONS
=cut
my $verbose = 0;     # invoke with "--verbose" to turn on more output.
my @words;           # word(s) to search for, might be broken up.
my $comey = "\"Our national identity is being remade in real time.  What had once seemed a bitter and divided society now seems more like a nation of people finding creative ways to show up for one another.\" - \@nytdavidbrooks";
my $string = $comey; # string to search within.


=head2 SUBROUTINE DECLARATIONS
=cut
sub main();


=head2 MAIN FUNCTION

Note that we first call setup_aspect_log(), and THEN exit main() -- previously I had the call to setup_aspect_log() inside the
main() sub, so it wasn't showing "Entering" and "Leaving" main(); now it will.

=cut
exit main();


=head2 SUBROUTINE DEFINITIONS
=cut
=head2 main

Main routine, which will try to find a word in another string.  Exits with errorlevel 0 if found, 1 otherwise.

=cut
sub main() {
  # Return code; default to failure.
  my $rc = -1;

  # First, validate our options.
  GetOptions( "verbose"  => \$verbose,
              "word=s"   => \@words,
              "string=s" => \$string,
            ) or die "Error in command line arguments.\n";
  # Any remaining bare args should go into @words.
  push @words, @ARGV;
  
  # Check that we have a word and string passed in.
  if ( scalar @words == 0 or !defined $string ) {
    die "Error: must define both 'word' and 'string'.";
  }

  # Get the results, and display them (in the subroutine).
  my $found = find_words_in_string( $string, @words );
  return $found ? 0 : 1; # errorlevel is basically reverse of the truth :)
}


=head2 find_word_in_string

Given a string and one or more words, see if each word is in the string.

Returns true if all were found, false if not.

=cut
sub find_words_in_string($@) {
  my ($string, @words) = @_;

  print "Searching [$string]\n";
  my $rc = 0; # default to failure
  # Planning this out, I think I can do this with a regex.  Just add ".*" between each character of $word, then search.
  # Wrap that in a loop for each word, and we're good.
  my $prev_found = 1; # initially success
  foreach my $w ( @words ) {
    my @word = split //, $w;
    my $search = join ".*", @word;
    my $is_in = $string =~ /$search/i;
    print "  Searching for [$w]: " . ($is_in ? "" : "NOT ") . "found.\n";
    if ( $prev_found ) {
        if ( $is_in ) {
            $rc = 1;
        } else {
          $rc = $prev_found = 0; # will return failure; however, continue searching for other words.
        }
    }
  }
  print "Returning [$rc] " . ($rc ? "ALL FOUND" : "NOT all found") . ".\n";
  return $rc;
}

23235686? ago

This comment was linked from this anonymous v/QRV submission.

Posted automatically (#102010) by the SearchVoat.co Cross-Link Bot. You can suppress these notifications by appending a forward-slash(/) to your Voat link. More information here.

23235667? ago

I turned this into a post, over here: https://voat.co/v/QRV/3745761