Skip to content

Commit

Permalink
cryptogram: Make an easy mode option too
Browse files Browse the repository at this point in the history
  • Loading branch information
Rosuav committed Jul 28, 2024
1 parent be2752d commit 1aac03c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions cryptogram.pike
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
Regexp.SimpleRegexp nonword = Regexp.SimpleRegexp("[^A-Z ]");
string make_cryptogram(string plain) {
sscanf(plain, "%[0-9. ]%s", string pfx, plain);
string stripped = nonword->replace(upper_case(plain), "");
stripped = upper_case(plain); //Easy mode: keep the punctuation.
array letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" / 1;
mapping cipher = mkmapping(letters, Array.shuffle(letters + ({ })));
return replace(stripped, cipher);
return pfx + replace(stripped, cipher);
}

int main(int argc, array(string) argv) {
foreach (argv[1..], string arg) {
arg = Stdio.read_file(arg) || arg;
foreach (arg / "\n", string line)
write("%s\n%s\n", line, make_cryptogram(line));
//write("%s\n%s\n", line, make_cryptogram(line)); //Compare?
write("%s\n", make_cryptogram(line)); //Or just show the puzzles?
}
}

0 comments on commit 1aac03c

Please sign in to comment.