-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.cs
192 lines (177 loc) · 6.8 KB
/
Form1.cs
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication9
{
public partial class Form1 : Form
{
const string SharedSecret = "rath/Haste. Grace or Discipline for survivability. Grace if with a group of ES users, Discipline if solo. HatrJ*()!G*Hjkasgasikg891gjh";
public Form1()
{
InitializeComponent();
openFileDialog1.Filter = "Text files(*.txt)|*.txt|All files(*.*)|*.*";
openFileDialog2.Filter = "Text files(*.txt)|*.txt|All files(*.*)|*.*";
saveFileDialog1.Filter = "Text files(*.txt)|*.txt|All files(*.*)|*.*";
saveFileDialog2.Filter = "Text files(*.txt)|*.txt|All files(*.*)|*.*";
saveFileDialog3.Filter = "Text files(*.txt)|*.txt|All files(*.*)|*.*";
}
private void button1_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.Cancel)
return;
Slovar.fn = openFileDialog1.FileName;
Slovar.File_To_List();
load();
}
private void button2_Click(object sender, EventArgs e)
{
if (Slovar.Poisk(textBox1.Text) != -1)
MessageBox.Show("Найдено в строке: " + Slovar.Poisk(textBox1.Text).ToString(), "Поиск", MessageBoxButtons.OK);
else
MessageBox.Show("Не найдено.", "Не найдено", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
private void button3_Click(object sender, EventArgs e)
{
if (Slovar.Poisk(textBox1.Text) != -1)
MessageBox.Show("Удалено в строке:" + Slovar.Ydoli(textBox1.Text).ToString(), "Del", MessageBoxButtons.OK);
else
MessageBox.Show("Не найдено.", "Не найдено", MessageBoxButtons.OK, MessageBoxIcon.Error);
load();
}
public void load()
{
Slovar.list.Sort();
textBox2.Text = "";
for (int i = 0; i < Slovar.list.Count; i++)
if (Slovar.list[i] != "")
if (i < Slovar.list.Count-1)
textBox2.Text += Slovar.list[i] + Environment.NewLine;
else textBox2.Text += Slovar.list[i];
}
private void button4_Click(object sender, EventArgs e)
{
if (saveFileDialog1.ShowDialog() == DialogResult.Cancel)
return;
string filename = saveFileDialog1.FileName;
System.IO.File.WriteAllText(filename, textBox2.Text);
MessageBox.Show("Файл сохранен");
}
private void button5_Click(object sender, EventArgs e)
{
if (Slovar.Poisk(textBox1.Text) == -1)
{
Slovar.Dobavka(textBox1.Text);
MessageBox.Show("Добавлено!", ":D", MessageBoxButtons.OK);
}
else
MessageBox.Show("Уже существует!", "Повтор", MessageBoxButtons.OK, MessageBoxIcon.Error);
load();
}
private void button6_Click(object sender, EventArgs e)
{
if (Slovar.PoiskPoSlogam(textBox1.Text) != "")
textBox3.Text = Slovar.PoiskPoSlogam(textBox1.Text);
else
MessageBox.Show("Не найдено.", "Не найдено", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
private void button7_Click(object sender, EventArgs e)
{
if (saveFileDialog2.ShowDialog() == DialogResult.Cancel)
return;
string filename = saveFileDialog2.FileName;
System.IO.File.WriteAllText(filename, textBox3.Text);
MessageBox.Show("Файл сохранен");
}
private void button8_Click(object sender, EventArgs e)
{
var encryptedStringAES = Crypto.EncryptStringAES(textBox2.Text, SharedSecret);
if (saveFileDialog1.ShowDialog() == DialogResult.Cancel)
return;
string filename = saveFileDialog1.FileName;
System.IO.File.WriteAllText(filename, encryptedStringAES);
MessageBox.Show("Файл зашифрован");
}
private void button9_Click(object sender, EventArgs e)
{
if (openFileDialog2.ShowDialog() == DialogResult.Cancel)
return;
string netxt = System.IO.File.ReadAllText(openFileDialog2.FileName);
textBox2.Text = Crypto.DecryptStringAES(netxt, SharedSecret);
Slovar.list = new List<string>(textBox2.Lines);
load();
}
}
class Slovar
{
static public string fn = "Словарь.txt";
static public List<string> list = new List<string>();
static public bool File_To_List() // загрузить файл в список
{
list.Clear();
try
{
System.IO.StreamReader f = new System.IO.StreamReader(fn);
while (!f.EndOfStream)
{
list.Add(f.ReadLine());
}
f.Close();
return true;
}
catch
{
MessageBox.Show("Ошибка доступа к файлу!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
}
static public int Ydoli(string slovo)
{
for (int i = 0; i < list.Count; i++)
{
if (list[i] == slovo && slovo != "")
{
list[i] = "";
return i;
}
}
return -1;
}
static public void Dobavka(string slovo)
{
list.Add(slovo);
}
static public int Poisk(string slovo)
{
for (int i = 0; i < list.Count; i++)
{
if (list[i] == slovo && slovo != "")
{
return i;
}
}
return -1;
}
static public string PoiskPoSlogam(string slovo)
{
string otv = "";
for (int i = 0; i < list.Count; i++)
{
for(int s = 0,q=0; s < slovo.Length; s++){
if ((list[i].Length >=slovo.Length) && ((list[i])[s] == slovo[s]) && (slovo != ""))
{
++q;
if (q == slovo.Length)
otv += list[i] + Environment.NewLine;
}
}
}
return otv;
}
}
}