-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.cs
179 lines (165 loc) · 4.68 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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Kriptotubes2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private String GetFileName(String filter)
{
OpenFileDialog open = new OpenFileDialog();
open.Filter = filter;
open.RestoreDirectory = true;
if (open.ShowDialog(this) == DialogResult.OK)
{
return open.FileName;
}
else
{
return null;
}
}
private void button1_Click(object sender, EventArgs e)
{
string fileName = GetFileName("Text Files (*.txt)|*.txt");
if (fileName != null)
{
textBox1.Text = fileName;
}
}
private void button2_Click(object sender, EventArgs e)
{
if (textBox1.Text.Length > 0)
{
String file = textBox1.Text;
try
{
textBox2.Text = File.ReadAllText(file);
}
catch (IOException)
{
}
}
}
private String convertToBinary(String s)
{
String result = String.Empty;
if (s.Length > 0)
{
foreach (char ch in textBox3.Text)
{
result += Convert.ToString((int)ch, 2);
}
}
else
{
result = "0";
}
return result;
}
private long splitK(String b)
{
int part = b.Length / 2;
int step = b.Length;
String Z1 = String.Empty;
String Z2 = String.Empty;
Z1 += b.Substring(0, part);
Z2 += b.Substring(part);
long C1 = Convert.ToInt64(Z1, 2);
long C2 = Convert.ToInt64(Z2, 2);
long C3 = C1 + C2;
return C3;
}
private String intToBinary(long C)
{
String Z3 = Convert.ToString(C, 2);
return Z3;
}
private String checkBinaryLength(String Z)
{
int X = Z.Length;
int y;
long V;
String I = String.Empty;
if (X > 8)
{
y = Z.Length;
while (y > 8)
{
V = splitK(Z);
Z = intToBinary(V);
y = Z.Length;
}
//I = Z;
}
else if (X < 8)
{
while(Z.Length < 8)
Z += "0";
//I = Z;
}
I = Z;
return I;
}
private String splitPText(String P)
{
while (P.Length % 8 != 0)
P += "0";
int part = P.Length / 8;
int step = P.Length;
String Z1 = String.Empty;
Z1 += P.Substring(0, 8);
return Z1;
}
private String splitKey(String K)
{
while (K.Length % 8 != 0)
K += "0";
int part = K.Length / 8;
int step = K.Length;
String Z1 = String.Empty;
Z1 += K.Substring(0, 8);
return Z1;
}
private void button3_Click(object sender, EventArgs e)
{
String a = textBox3.Text;
textBox4.Text = convertToBinary(a);
String b = textBox4.Text;
//int part = b.Length / 2;
//int step = b.Length;
//String Z1 = String.Empty;
//String Z2 = String.Empty;
//for (int i = 0; i < step; i += part)
//{
// if (i + 2 > step)
// part = step - i;
//Z1 += b.Substring(0, part);
//Z2 += b.Substring(part);
//}
//textBox1.Text = Z1;
//textBox2.Text = Z2;
//int C1 = Convert.ToInt32(textBox1.Text, 2);
//int C2 = Convert.ToInt32(textBox2.Text, 2);
//textBox3.Text = C1.ToString();
//textBox4.Text = C2.ToString();
//int C3 = C1 + C2;
//textBox2.Text = C3.ToString();
long C3 = splitK(b);
String Z3 = Convert.ToString(C3, 2);
textBox1.Text = Z3;
textBox1.Text = checkBinaryLength(Z3);
textBox2.Text = splitPText(b);
}
}
}