| 1 | #! /usr/bin/perl |
| 2 | |
| 3 | # Reads ptab.in or similarly-formatted file; writes a calc script to check |
| 4 | # it. |
| 5 | |
| 6 | while (<>) { |
| 7 | next if /^\s*(\#[^!]|$)/; |
| 8 | @F = split; |
| 9 | if ($F[0] eq "group") { |
| 10 | $group = $F[1]; |
| 11 | $_ = <>; @F = split; $F[0] eq "p" or die $F[0]; $p = $F[1]; |
| 12 | $_ = <>; @F = split; $F[0] eq "q" or die $F[0]; $q = $F[1]; |
| 13 | $_ = <>; @F = split; $F[0] eq "g" or die $F[0]; $g = $F[1]; |
| 14 | print <<EOF; |
| 15 | print "testing $group..."; |
| 16 | p = $p; |
| 17 | q = $q; |
| 18 | g = $g; |
| 19 | if (!ptest(p)) print " p not prime"; |
| 20 | if (!ptest(q)) print " q not prime"; |
| 21 | if ((p - 1)%q) print " q doesn't divide p - 1"; |
| 22 | h = (p - 1)/q; |
| 23 | if (pmod(g, q, p) != 1) print " g doesn't have order q"; |
| 24 | if (pmod(g, h, p) == 1) print " g generates overly large group"; |
| 25 | ff = 2; |
| 26 | EOF |
| 27 | $ll = 0; |
| 28 | for (;;) { |
| 29 | $_ = <>; @F = split; $F[0] eq "#:factor" or last; $f = $F[1]; |
| 30 | print <<EOF; |
| 31 | f = $f; |
| 32 | if (!ptest(f)) print " factor not prime", f; |
| 33 | ff *= f; |
| 34 | EOF |
| 35 | $ll = 1; |
| 36 | } |
| 37 | if ($ll) { |
| 38 | print <<EOF; |
| 39 | if (ff != p - 1) print " missing factors"; |
| 40 | EOF |
| 41 | } |
| 42 | } |
| 43 | } |