-
Notifications
You must be signed in to change notification settings - Fork 0
/
Coder.cs
58 lines (54 loc) · 2.23 KB
/
Coder.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
using System.ComponentModel;
using System.Linq;
using System.Text.RegularExpressions;
namespace Laba1
{
public class Coder
{
public static void Coding()
{
var coder = new BackgroundWorker { WorkerReportsProgress = true };
coder.DoWork += coder_DoWork;
coder.ProgressChanged += coder_ProgressChanged;
coder.RunWorkerCompleted += coder_RunWorkerCompleted;
coder.RunWorkerAsync();
}
private static void coder_DoWork(object sender, DoWorkEventArgs e)
{
var i = 0;
switch (Processor.Lang)
{
case Languages.Ru:
foreach (var c in Processor.Text.Where(char.IsLetter))
{
var reg = new Regex(Processor.Key[i].ToString());
var reg1 = new Regex(c.ToString());
Processor.Cipertext += char.IsLower(c)
? Processor.SmlRus[((reg1.Match(Processor.SmlRus).Index) + reg.Match(Processor.SmlRus).Index) % 33]
: Processor.BigRus[((reg1.Match(Processor.BigRus).Index) + reg.Match(Processor.SmlRus).Index) % 33];
i++;
(sender as BackgroundWorker).ReportProgress(i);
}
break;
case Languages.Eng:
foreach (var c in Processor.Text.Where(char.IsLetter))
{
Processor.Cipertext += char.IsLower(c)
? Processor.SmlEng[((c - 'a') + (Processor.Key[i] - 'a')) % 26]
: Processor.BigEng[((c - 'A') + (Processor.Key[i] - 'a')) % 26];
i++;
(sender as BackgroundWorker).ReportProgress(i);
}
break;
}
}
private static void coder_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
Processor.Bar.Value = e.ProgressPercentage;
}
private static void coder_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
Processor.Goal.Text = Processor.Cipertext;
}
}
}