-
Notifications
You must be signed in to change notification settings - Fork 1
/
Form1.cs
268 lines (214 loc) · 8.3 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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace TestEncryptDecrypt
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnEncrypt_Click(object sender, EventArgs e)
{
try
{
EncryptDecrypt.MyEncryptor enc = new EncryptDecrypt.MyEncryptor(txtPhrase.Text.Trim());
txtDecrypt.Text = enc.Encrypt(txtEncrypt.Text.Trim());
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void btnDecrypt_Click(object sender, EventArgs e)
{
try
{
EncryptDecrypt.MyEncryptor enc = new EncryptDecrypt.MyEncryptor(txtPhrase.Text.Trim());
txtEncrypt.Text = enc.Decrypt(txtDecrypt.Text.Trim());
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void btnBrowseDecrypt_Click(object sender, EventArgs e)
{
//Setup the open dialog.
openFileDialog1.FileName = "";
openFileDialog1.Title = "Pilih file yang akan di dekripsi";
openFileDialog1.InitialDirectory = @"C:\";
openFileDialog1.Filter = "Encrypted Files (*.encrypt) | *.encrypt";
string strFileToDecrypt = "";
string strOutputDecrypt = "";
//Find out if the user chose a file.
if(openFileDialog1.ShowDialog() == DialogResult.OK)
{
strFileToDecrypt = openFileDialog1.FileName;
txtFileToDecrypt.Text = strFileToDecrypt;
int iPosition;
/* Get the position of the last "\" in the OpenFileDialog.FileName path.
* -1 is when the character your searching for is not there.
* IndexOf searches from left to right.*/
iPosition = strFileToDecrypt.LastIndexOf(".encrypt");
if((iPosition == -1) || (iPosition != (strFileToDecrypt.Length-8)))
{
MessageBox.Show("File salah. Tolomg pilih file enkripsi yang benar.");
}
//strOutputFile = the file path minus the last 8 characters (.encrypt)
strOutputDecrypt = strFileToDecrypt.Substring(0, strFileToDecrypt.Length - 8);
//Assign strOutputFile to the position after the last "\" in the path.
iPosition = strOutputDecrypt.IndexOf("z_z");
if (iPosition == -1)
{
strOutputDecrypt = strOutputDecrypt + ".dat";
}
else
{
strOutputDecrypt = strOutputDecrypt.Replace("z_z", ".");
}
txtDestinationDecrypt.Text = strOutputDecrypt;
//Update buttons
btnFileDecrypt.Enabled = true;
}
}
private void btnBrowseEncrypt_Click(object sender, EventArgs e)
{
//Setup the open dialog.
openFileDialog1.FileName = "";
openFileDialog1.Title = "Pilih file yang akan di enkripsi";
openFileDialog1.InitialDirectory = @"C:\";
// openFileDialog1.Filter = "Encrypted Files (*.encrypt) | *.encrypt";
string strFileToEncrypt = "";
string strOutputEncrypt = "";
string strExtension = "";
//Find out if the user chose a file.
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
strFileToEncrypt = openFileDialog1.FileName;
txtFileToEncrypt.Text = strFileToEncrypt;
int iPosition;
/* Get the position of the last "\" in the OpenFileDialog.FileName path.
* -1 is when the character your searching for is not there.
* IndexOf searches from left to right.*/
iPosition = strFileToEncrypt.LastIndexOf(".");
if (iPosition == -1)
{
MessageBox.Show("File salah. Tolong pilih file yang benar.");
}
//strOutputFile = the file path minus the last 8 characters (.encrypt)
strExtension = strFileToEncrypt.Substring(iPosition, (strFileToEncrypt.Length - iPosition));
//Assign strOutputFile to the position after the last "\" in the path.
string strEncryptedExt = "z_z" + strExtension.Substring(1) + ".encrypt";
strOutputEncrypt = strFileToEncrypt.Replace(strExtension, strEncryptedExt);
txtDestinationEncrypt.Text = strOutputEncrypt;
//Update buttons
btnFileEncrypt.Enabled = true;
}
}
private void btnFileDecrypt_Click(object sender, EventArgs e)
{
try
{
if (txtConPassDecrypt.Text != txtPassDecrypt.Text)
{
txtConPassDecrypt.Text = "";
MessageBox.Show("Password tidak sesuai. Tolong coba lagi.");
return;
}
string strSecretKey = txtPassDecrypt.Text.Trim();
EncryptDecrypt.MyEncryptor enc = new EncryptDecrypt.MyEncryptor(strSecretKey);
enc.Decrypt(txtFileToDecrypt.Text, txtDestinationDecrypt.Text);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void btnFileEncrypt_Click(object sender, EventArgs e)
{
try
{
if (txtConPassEncrypt.Text != txtPassEncrypt.Text)
{
txtConPassEncrypt.Text = "";
MessageBox.Show("Password tidak sesuai. Tolong coba lagi.");
return;
}
string strSecretKey = txtPassEncrypt.Text.Trim();
EncryptDecrypt.MyEncryptor enc = new EncryptDecrypt.MyEncryptor(strSecretKey);
enc.Encrypt(txtFileToEncrypt.Text, txtDestinationEncrypt.Text);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void tabPage1_Click(object sender, EventArgs e)
{
}
private void tabPage1_Click_1(object sender, EventArgs e)
{
}
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void txtConPassDecrypt_TextChanged(object sender, EventArgs e)
{
}
private void txtPassDecrypt_TextChanged(object sender, EventArgs e)
{
}
private void Label8_Click(object sender, EventArgs e)
{
}
private void Label7_Click(object sender, EventArgs e)
{
}
private void Label5_Click(object sender, EventArgs e)
{
}
private void Label6_Click(object sender, EventArgs e)
{
}
private void txtFileToDecrypt_TextChanged(object sender, EventArgs e)
{
}
private void txtDestinationDecrypt_TextChanged(object sender, EventArgs e)
{
}
private void tabFileDecryption_Click(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void lblEncrypted_Click(object sender, EventArgs e)
{
}
private void Label1_Click(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void label10_Click(object sender, EventArgs e)
{
}
private void label11_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("https://cryptordev.github.io/");
}
private void label12_Click(object sender, EventArgs e)
{
}
}
}