Repository navigation
Expand file tree
/
Copy pathMainForm.cs
More file actions
156 lines (125 loc) · 4.36 KB
/
Copy pathMainForm.cs
File metadata and controls
156 lines (125 loc) · 4.36 KB
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
using lab3_rc5.Algorythms.RC5;
using System;
using System.Windows.Forms;
namespace lab3_rc5
{
public partial class MainForm : Form
{
private byte roundsNumber = 12;
public MainForm()
{
InitializeComponent();
}
//encrypting file
private void button1_Click(object sender, EventArgs e)
{
string plainFilePath = textBox1.Text;
string cryptedFilePath = textBox2.Text;
string password = textBox3.Text;
try
{
if (plainFilePath.Equals(""))
{
ErrorMessage("Choose source file.");
}
else if (cryptedFilePath.Equals(""))
{
ErrorMessage("Choose destination file.");
}
else if (password.Equals(""))
{
ErrorMessage("Enter phrase");
}
else
{
try
{
var encryptor = new RC5Algorithm(password, 16, 12);
encryptor.Encrypt(plainFilePath, cryptedFilePath);
InfoMessage("Success.");
}
catch (Exception ex)
{
ErrorMessage(ex.Message);
}
}
}
catch (Exception ex)
{
ErrorMessage(ex.Message);
}
}
//decrypting file
private void button2_Click(object sender, EventArgs e)
{
string cryptedFilePath = textBox1.Text;
string plainFilePath = textBox2.Text;
string password = textBox3.Text;
try
{
if (plainFilePath.Equals(""))
{
ErrorMessage("Choose source file.");
}
if (cryptedFilePath.Equals(""))
{
ErrorMessage("Choose destination file.");
}
if (password.Equals(""))
{
ErrorMessage("Enter phrase");
}
try
{
var encryptor = new RC5Algorithm(password, 16, 12);
encryptor.Decrypt(cryptedFilePath, plainFilePath);
InfoMessage("Success");
}
catch (Exception ex)
{
ErrorMessage(ex.Message);
}
}
catch (Exception ex)
{
ErrorMessage(ex.Message);
}
}
//uploading source file
private void button3_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.ShowHelp = true;
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
openFileDialog1.FilterIndex = 2;
openFileDialog1.RestoreDirectory = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
string filename = openFileDialog1.FileName;
textBox1.Text = filename;
}
}
//uploading destination file
private void button4_Click(object sender, EventArgs e)
{
SaveFileDialog openFileDialog1 = new SaveFileDialog();
openFileDialog1.ShowHelp = true;
openFileDialog1.Filter = "crypt files (*.crypt)|*.crypt|All files (*.*)|*.*";
openFileDialog1.FilterIndex = 2;
openFileDialog1.RestoreDirectory = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
string filename = openFileDialog1.FileName;
textBox2.Text = filename;
}
}
private void ErrorMessage(string text)
{
MessageBox.Show(text, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
private void InfoMessage(string text)
{
MessageBox.Show(text, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}