for my $p ( [529,199,442,183,393],[174,603,481,399,664],[483,139,314,59] ) {
####
use strict;
my $probe = $ARGV[0];
print "probing for $probe\n";
our @probes = split //,$probe;
undef $/;
our $data = lc . "jkwy" x 10;
$data =~ s/(\015|\012)+/ /g; # Needed to solve newline mismatches
our @letter = split //, $data;
sub poleval {
my ($x, $r) = (shift, 0);
$r = ( $r * $x + $_ ) % 683 for @_;
$r;
}
sub get_letter {
my $val = shift;
return grep { $letter[$_] eq $val } 0..$#letter;
}
my @p0 = get_letter($probes[0]);
my @p1 = get_letter($probes[1]);
my @p2 = get_letter($probes[2]);
my @p3 = get_letter($probes[3]);
my @p4 = get_letter($probes[4]);
my $p5 = $probes[5];
my $total = scalar(@p0)*scalar(@p1)*scalar(@p2)
*scalar(@p3)*scalar(@p4);
print "Estimated $total count\n";
my $count = $#letter;
my $comb = 0;
my ($a, $b, $c, $d, $e, $r, $x, $y, $z, $q, $ap, $bp, $cp);
my ($app, $bpp);
my ($x0, $x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9);
for $a (@p0) {
for $b (@p1) {
for $c (@p2) {
$ap = ($c - $a) - 2*($b - $a);
for $d (@p3) {
$bp = ($d - $a) - 3*($b - $a);
for $e (@p4) {
$cp = ($e - $a) - 4*($b - $a);
$app = ($bp - 3*$ap);
$bpp = ($cp - 6*$ap);
# 370 is the inverse of 24 mod 683.
$r = (370*($bpp - 4*$app)) % 683;
# 114 is the inverse of 6 mod 683.
$x = (114*($app - 36*$r)) % 683;
# 342 is the inverse of 2 mod 683.
$y = (342*($ap - 14*$r - 6*$x)) % 683;
$z = ($b - $a - $r - $x - $y) % 683;
$x5 = poleval(5,$r,$x,$y,$z,$a);
next if $x5 > $count;
next if ($letter[$x5] ne $p5);
$x6 = poleval(6,$r,$x,$y,$z,$a);
next if $x6 > $count;
$x7 = poleval(7,$r,$x,$y,$z,$a);
next if $x7 > $count;
$x8 = poleval(8,$r,$x,$y,$z,$a);
next if $x8 > $count;
$x9 = poleval(9,$r,$x,$y,$z,$a);
next if $x9 > $count;
print "possible at $r, $x, $y, $z, $a: ";
print $probes[0],$probes[1],$probes[2],$probes[3];
print $probes[4],$letter[$x5],$letter[$x6],$letter[$x7];
print $letter[$x8],$letter[$x9],"\n";
}
}
}
}
}
__DATA__
Lupus et agnus
Ad rivum eundem lupus et agnus venerant,
siti compulsi. Superior stabat lupus,
longeque inferior agnus. Tunc fauce improba
latro incitatus iurgii causam intulit;
'Cur' inquit 'turbulentam fecisti mihi
aquam bibenti?' Laniger contra timens
'Qui possum, quaeso, facere quod quereris, lupe?
A te decurrit ad meos haustus liquor'.
Repulsus ille veritatis viribus
'Ante hos sex menses male' ait 'dixisti mihi'.
Respondit agnus 'Equidem natus non eram'.
'Pater hercle tuus' ille inquit 'male dixit mihi';
atque ita correptum lacerat iniusta nece.
Haec propter illos scripta est homines fabula
qui fictis causis innocentes opprimunt.
####
492, 258, 236, 558, 276: any excuse
226, 640, 286, 616, 465: any excuse
202, 487, 474, 15, 680: will serve
323, 527, 255, 84: a tyrant
501, 663, 511, 136: a tyrant
634, 447, 626, 165: a tyrant
107, 489, 228, 200: a tyrant
61, 535, 38, 216: a tyrant
625, 232, 416, 269: a tyrant
148, 199, 463, 303: a tyrant
380, 162, 314, 303: a tyrant
255, 535, 86, 326: a tyrant
610, 425, 390, 361: a tyrant
88, 470, 603, 458: a tyrant
645, 617, 159, 458: a tyrant
350, 669, 352, 514: a tyrant
242, 115, 22, 535: a tyrant
394, 46, 227, 535: a tyrant
307, 18, 392, 596: a tyrant