Walk 制作词频统计工具

使用 walk 来制作golnag的图形界面

需求分析

输入一段密文,通过计算每个字母的词频,根据概率和枚举推算出每个字母解密后的字母,获取解密后的密文

窗口实现

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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83

func main() {
_,_ = MainWindow{
AssignTo: &mw,
Title: "词频统计分析",
Font: Font{
PointSize: 12,
},
MinSize: Size{Width: 600, Height: 400},
Layout: VBox{},

Children: []Widget{

Composite{
Layout: HBox{},
Children: []Widget{
Label{
TextAlignment: AlignCenter,
Text: "输入",
},
Label{
TextAlignment: AlignCenter,
Text: "",
},
Label{
TextAlignment: AlignCenter,
Text: "输出",
},
},
},
Composite{
Layout: HBox{},
//MinSize: Size{Width: 400, Height: 370},
Children: []Widget{

TextEdit{
AssignTo: &inTE,
VScroll: true,
OnTextChanged: SaveText,
},
Composite{
Layout: VBox{},
Children: []Widget{

PushButton{
Text: "统计频",
OnClicked: GetRate,
},

Label{
TextAlignment: AlignCenter,
Text: "替换",
},

LineEdit{

AssignTo: &lineA,
},
Label{
TextAlignment: AlignCenter,
Text: "为",
},
LineEdit{

AssignTo: &lineB,
},
Label{
TextAlignment: AlignCenter,
Text: "-->",
},
PushButton{
Text: "替换字",
OnClicked: ChangeText,
},
},
},
TextEdit{AssignTo: &outTE, ReadOnly: true, VScroll: true},
},
},

},
}.Run()
}

效果展示

词频统计分析

替换字母获得解密后的密文