-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfindbykey.go
48 lines (40 loc) · 1020 Bytes
/
findbykey.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"fmt"
"log"
"os"
"cryptoquip/qp"
)
func main() {
if len(os.Args) < 3 {
fmt.Fprintf(os.Stderr, "Find matches in dictionary by word shape\n")
fmt.Fprintf(os.Stderr, "usage: %s cleartext.dictionary word [word...]\n", os.Args[0])
return
}
dict, err := qp.NewShapeDict(os.Args[1])
if err != nil {
log.Fatal(err)
}
allLetters := qp.NewRunesDict(dict)
for _, str := range os.Args[2:] {
config := qp.StringConfiguration(str)
fmt.Printf("%s\n%s\n\n", str, config)
configMatches := dict[config]
for _, m := range configMatches {
fmt.Printf("\t%s\n", m)
}
fmt.Printf("%d matches\n", len(configMatches))
if entry, ok := allLetters[config]; ok {
fmt.Printf("Found letters for configuration %s\n", config)
for i := 0; i < entry.Length; i++ {
fmt.Printf("Letters at %d: ", i)
for r, _ := range entry.Runes[i] {
fmt.Printf("%c ", r)
}
fmt.Println()
}
} else {
fmt.Printf("Did not find letters for configuration %s\n", config)
}
}
}