Skip to content

Commit f20890f

Browse files
author
Даниил Рудь
committed
Add project files.
1 parent 1f06cdb commit f20890f

12 files changed

+1048
-0
lines changed

App.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
5+
</startup>
6+
</configuration>

Form1.Designer.cs

Lines changed: 325 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Form1.cs

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel;
4+
using System.Data;
5+
using System.Drawing;
6+
using System.IO;
7+
using System.Linq;
8+
using System.Text;
9+
using System.Threading.Tasks;
10+
using System.Windows.Forms;
11+
using System.Security.Cryptography;
12+
using System.Diagnostics;
13+
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
14+
15+
namespace SymmetricEncryptionAlgorithms
16+
{
17+
public partial class Form1 : Form
18+
{
19+
private byte[] key;
20+
private byte[] IV;
21+
private byte[] cipherBytes;
22+
List<CipherMode> cipherModesLocal = new List<CipherMode>() { CipherMode.ECB, CipherMode.CBC, CipherMode.CFB };
23+
24+
private Dictionary<string, long> dictionaryCipherResults;
25+
private Dictionary<string, long> dictionaryDecipherResults;
26+
public Form1()
27+
{
28+
InitializeComponent();
29+
30+
openFileDialog1.Filter = "Text files(*.txt)|*.txt|All files(*.*)|*.*";
31+
32+
string[] cipherTypes = { "All", "DES", "3DES", "RC2", "Rijndael", "AES" };
33+
string[] cipherModes = { "ECB", "CBC", "CFB" };
34+
35+
36+
comboBoxMethods.Items.AddRange(cipherTypes);
37+
comboBoxMethods.SelectedIndex = 0;
38+
comboBoxMode.Items.AddRange(cipherModes);
39+
40+
chartEncryption.Series.Clear();
41+
chartDecryption.Series.Clear();
42+
43+
for (int i = 1; i < cipherTypes.Length; i++)
44+
{
45+
chartEncryption.Series.Add(cipherTypes[i]);
46+
chartEncryption.Series[cipherTypes[i]].XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Auto;
47+
chartEncryption.Series[cipherTypes[i]].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Column;
48+
49+
chartDecryption.Series.Add(cipherTypes[i]);
50+
chartDecryption.Series[cipherTypes[i]].XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Auto;
51+
chartDecryption.Series[cipherTypes[i]].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Column;
52+
}
53+
}
54+
55+
private void buttonOpen_Click(object sender, EventArgs e)
56+
{
57+
if (openFileDialog1.ShowDialog() != DialogResult.Cancel)
58+
{
59+
string filename = openFileDialog1.FileName;
60+
string fileText = File.ReadAllText(filename);
61+
textBoxSource.Text = fileText;
62+
}
63+
}
64+
65+
private void buttonStart_Click(object sender, EventArgs e)
66+
{
67+
SymmetricAlgorithm saDES = DES.Create();
68+
SymmetricAlgorithm sa3DES = TripleDES.Create();
69+
SymmetricAlgorithm saRC2 = RC2.Create();
70+
SymmetricAlgorithm saRijndael = Rijndael.Create();
71+
SymmetricAlgorithm saAES = Aes.Create();
72+
73+
switch (comboBoxMethods.SelectedItem.ToString())
74+
{
75+
case "All":
76+
RunCipher(new List<SymmetricAlgorithm> { saDES, sa3DES, saRC2, saRijndael, saAES }, cipherModesLocal, new List<string> { "DES", "3DES", "RC2", "Rijndael", "AES" });
77+
break;
78+
case "DES":
79+
RunCipher(new List<SymmetricAlgorithm> { saDES }, cipherModesLocal, new List<string> { "DES" });
80+
break;
81+
case "3DES":
82+
RunCipher(new List<SymmetricAlgorithm> { sa3DES }, cipherModesLocal, new List<string> { "3DES" });
83+
break;
84+
case "RC2":
85+
RunCipher(new List<SymmetricAlgorithm> { saRC2 }, cipherModesLocal, new List<string> { "RC2" });
86+
break;
87+
case "Rijndael":
88+
RunCipher(new List<SymmetricAlgorithm> { saRijndael }, cipherModesLocal, new List<string> { "Rijndael" });
89+
break;
90+
case "AES":
91+
RunCipher(new List<SymmetricAlgorithm> { saAES }, cipherModesLocal, new List<string> { "AES" });
92+
break;
93+
}
94+
}
95+
96+
private void RunCipher(List<SymmetricAlgorithm> symmetricAlgorithm, List<CipherMode> cipherModesLocal, List<string> symmetricAlgorithmList)
97+
{
98+
dictionaryCipherResults = new Dictionary<string, long>();
99+
dictionaryDecipherResults = new Dictionary<string, long>();
100+
chartEncryption.Series.Clear();
101+
chartDecryption.Series.Clear();
102+
textBoxEncrypted.Clear();
103+
textBoxDecrypted.Clear();
104+
for (int i = 0; i < symmetricAlgorithm.Count; i++)
105+
{
106+
for (int j = 0; j < cipherModesLocal.Count; j++)
107+
{
108+
progressBar1.PerformStep();
109+
Stopwatch stopwatch = new Stopwatch();
110+
stopwatch.Start();
111+
symmetricAlgorithm[i].GenerateKey();
112+
key = symmetricAlgorithm[i].Key;
113+
symmetricAlgorithm[i].GenerateIV();
114+
IV = symmetricAlgorithm[i].IV;
115+
symmetricAlgorithm[i].Mode = cipherModesLocal[j];
116+
symmetricAlgorithm[i].Padding = PaddingMode.PKCS7;
117+
118+
MemoryStream ms = new MemoryStream();
119+
CryptoStream cs = new CryptoStream(ms, symmetricAlgorithm[i].CreateEncryptor(), CryptoStreamMode.Write);
120+
byte[] plainbytes = Encoding.UTF8.GetBytes(textBoxSource.Text.ToCharArray());
121+
cs.Write(plainbytes, 0, plainbytes.Length);
122+
cs.Close();
123+
cipherBytes = ms.ToArray();
124+
ms.Close();
125+
stopwatch.Stop();
126+
127+
string ciphedText = Encoding.UTF8.GetString(cipherBytes);
128+
dictionaryCipherResults.Add(symmetricAlgorithmList[i] + " " + cipherModesLocal[j].ToString(), stopwatch.ElapsedTicks);
129+
textBoxEncrypted.Text += $"{symmetricAlgorithmList[i]} {cipherModesLocal[j]}: {ciphedText}\r\n";
130+
131+
stopwatch = new Stopwatch();
132+
stopwatch.Start();
133+
symmetricAlgorithm[i].Key = key;
134+
symmetricAlgorithm[i].IV = IV;
135+
MemoryStream ms1 = new MemoryStream(cipherBytes);
136+
CryptoStream cs1 = new CryptoStream(ms1, symmetricAlgorithm[i].CreateEncryptor(), CryptoStreamMode.Read);
137+
byte[] plainbytes1 = new Byte[cipherBytes.Length];
138+
cs1.Read(plainbytes1, 0, cipherBytes.Length);
139+
cs1.Close();
140+
ms1.Close();
141+
stopwatch.Stop();
142+
143+
string deciphedText = Encoding.UTF8.GetString(plainbytes);
144+
dictionaryDecipherResults.Add(symmetricAlgorithmList[i] + " " + cipherModesLocal[j], stopwatch.ElapsedTicks);
145+
textBoxDecrypted.Text += $"{symmetricAlgorithmList[i]} {cipherModesLocal[j]}: {deciphedText}\r\n";
146+
}
147+
}
148+
int counter = 0;
149+
foreach (KeyValuePair<string, long> item in dictionaryCipherResults)
150+
{
151+
chartEncryption.Series.Add(item.Key);
152+
chartEncryption.Series[counter].Points.AddY(item.Value);
153+
counter++;
154+
}
155+
counter = 0;
156+
foreach (KeyValuePair<string, long> item in dictionaryDecipherResults)
157+
{
158+
chartDecryption.Series.Add(item.Key);
159+
chartDecryption.Series[counter].Points.AddY(item.Value);
160+
counter++;
161+
}
162+
}
163+
164+
private void comboBoxMethods_SelectedIndexChanged(object sender, EventArgs e)
165+
{
166+
if (comboBoxMethods.SelectedItem.ToString() != "All")
167+
{
168+
comboBoxMode.SelectedIndex = 0;
169+
}
170+
else
171+
{
172+
comboBoxMode.SelectedIndex = -1;
173+
}
174+
}
175+
176+
private void comboBoxMode_SelectedIndexChanged(object sender, EventArgs e)
177+
{
178+
cipherModesLocal.Clear();
179+
comboBoxMode.Enabled = true;
180+
switch (comboBoxMode.SelectedItem != null ? comboBoxMode.SelectedItem.ToString() : "All")
181+
{
182+
case "All":
183+
cipherModesLocal.Add(CipherMode.ECB);
184+
cipherModesLocal.Add(CipherMode.CBC);
185+
cipherModesLocal.Add(CipherMode.CFB);
186+
comboBoxMode.SelectedIndex = -1;
187+
comboBoxMode.Text = "";
188+
comboBoxMode.Enabled = false;
189+
break;
190+
case "ECB":
191+
cipherModesLocal.Add(CipherMode.ECB);
192+
break;
193+
case "CBC":
194+
cipherModesLocal.Add(CipherMode.CBC);
195+
break;
196+
case "CFB":
197+
cipherModesLocal.Add(CipherMode.CFB);
198+
break;
199+
}
200+
}
201+
}
202+
}

Form1.resx

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<root>
3+
<!--
4+
Microsoft ResX Schema
5+
6+
Version 2.0
7+
8+
The primary goals of this format is to allow a simple XML format
9+
that is mostly human readable. The generation and parsing of the
10+
various data types are done through the TypeConverter classes
11+
associated with the data types.
12+
13+
Example:
14+
15+
... ado.net/XML headers & schema ...
16+
<resheader name="resmimetype">text/microsoft-resx</resheader>
17+
<resheader name="version">2.0</resheader>
18+
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
19+
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
20+
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
21+
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
22+
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
23+
<value>[base64 mime encoded serialized .NET Framework object]</value>
24+
</data>
25+
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
26+
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
27+
<comment>This is a comment</comment>
28+
</data>
29+
30+
There are any number of "resheader" rows that contain simple
31+
name/value pairs.
32+
33+
Each data row contains a name, and value. The row also contains a
34+
type or mimetype. Type corresponds to a .NET class that support
35+
text/value conversion through the TypeConverter architecture.
36+
Classes that don't support this are serialized and stored with the
37+
mimetype set.
38+
39+
The mimetype is used for serialized objects, and tells the
40+
ResXResourceReader how to depersist the object. This is currently not
41+
extensible. For a given mimetype the value must be set accordingly:
42+
43+
Note - application/x-microsoft.net.object.binary.base64 is the format
44+
that the ResXResourceWriter will generate, however the reader can
45+
read any of the formats listed below.
46+
47+
mimetype: application/x-microsoft.net.object.binary.base64
48+
value : The object must be serialized with
49+
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
50+
: and then encoded with base64 encoding.
51+
52+
mimetype: application/x-microsoft.net.object.soap.base64
53+
value : The object must be serialized with
54+
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
55+
: and then encoded with base64 encoding.
56+
57+
mimetype: application/x-microsoft.net.object.bytearray.base64
58+
value : The object must be serialized into a byte array
59+
: using a System.ComponentModel.TypeConverter
60+
: and then encoded with base64 encoding.
61+
-->
62+
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
63+
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
64+
<xsd:element name="root" msdata:IsDataSet="true">
65+
<xsd:complexType>
66+
<xsd:choice maxOccurs="unbounded">
67+
<xsd:element name="metadata">
68+
<xsd:complexType>
69+
<xsd:sequence>
70+
<xsd:element name="value" type="xsd:string" minOccurs="0" />
71+
</xsd:sequence>
72+
<xsd:attribute name="name" use="required" type="xsd:string" />
73+
<xsd:attribute name="type" type="xsd:string" />
74+
<xsd:attribute name="mimetype" type="xsd:string" />
75+
<xsd:attribute ref="xml:space" />
76+
</xsd:complexType>
77+
</xsd:element>
78+
<xsd:element name="assembly">
79+
<xsd:complexType>
80+
<xsd:attribute name="alias" type="xsd:string" />
81+
<xsd:attribute name="name" type="xsd:string" />
82+
</xsd:complexType>
83+
</xsd:element>
84+
<xsd:element name="data">
85+
<xsd:complexType>
86+
<xsd:sequence>
87+
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
88+
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
89+
</xsd:sequence>
90+
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
91+
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
92+
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
93+
<xsd:attribute ref="xml:space" />
94+
</xsd:complexType>
95+
</xsd:element>
96+
<xsd:element name="resheader">
97+
<xsd:complexType>
98+
<xsd:sequence>
99+
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
100+
</xsd:sequence>
101+
<xsd:attribute name="name" type="xsd:string" use="required" />
102+
</xsd:complexType>
103+
</xsd:element>
104+
</xsd:choice>
105+
</xsd:complexType>
106+
</xsd:element>
107+
</xsd:schema>
108+
<resheader name="resmimetype">
109+
<value>text/microsoft-resx</value>
110+
</resheader>
111+
<resheader name="version">
112+
<value>2.0</value>
113+
</resheader>
114+
<resheader name="reader">
115+
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
116+
</resheader>
117+
<resheader name="writer">
118+
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119+
</resheader>
120+
<metadata name="openFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
121+
<value>17, 17</value>
122+
</metadata>
123+
</root>

Program.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using System.Windows.Forms;
6+
7+
namespace SymmetricEncryptionAlgorithms
8+
{
9+
internal static class Program
10+
{
11+
/// <summary>
12+
/// The main entry point for the application.
13+
/// </summary>
14+
[STAThread]
15+
static void Main()
16+
{
17+
Application.EnableVisualStyles();
18+
Application.SetCompatibleTextRenderingDefault(false);
19+
Application.Run(new Form1());
20+
}
21+
}
22+
}

Properties/AssemblyInfo.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("SymmetricEncryptionAlgorithms")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("SymmetricEncryptionAlgorithms")]
13+
[assembly: AssemblyCopyright("Copyright © 2023")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("0ed4d2fe-d433-4341-88b9-64a988ce2922")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

0 commit comments

Comments
 (0)