Repository navigation
Expand file tree
/
Copy pathEncryptor.cs
More file actions
112 lines (94 loc) · 3.05 KB
/
Copy pathEncryptor.cs
File metadata and controls
112 lines (94 loc) · 3.05 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace EncryptionHeckingCode
{
public class Encryptor
{
public bool complete = false;
public string Result = null;
public virtual string Encrypt()
{
return "";
}
public virtual string Decrypt()
{
return "";
}
public virtual void Output(ref RichTextBox t)
{
t.Text = this.Result;
//self cancelling operation, nothing further to be done once text is generated and output
this.Stop();
}
public virtual void Start(bool Encrypt)
{
}
public virtual void Stop()
{
}
public class Key
{
/// <summary>
/// Encryption key and generator
/// </summary>
internal readonly string keyContent;
internal readonly int length;
/// <summary>
/// Randomly generated key
/// </summary>
/// <param name="length">desired length of the key</param>
/// <param name="alphanumeric">whether the key is alphanumeric (true) or not (false)</param>
public Key(int length, bool alphanumeric)
{
keyContent = Generate(length, alphanumeric);
length = keyContent.Length;
}
/// <summary>
/// User input key
/// </summary>
/// <param name="input"> key input by the user</param>
public Key(string input)
{
keyContent = input;
length = keyContent.Length;
}
//keeping this static because if we want to generate a new key we may as well generate a completely new object to ensure
//true random is implemented by not reusing the same random
internal static string Generate(int length, bool alphanumeric)
{
Random rnd = new Random();
string key = "";
List<char> alphabet = new List<char>();
int lower = 0, higher = 0, hook= 0, jump = 0;
if (alphanumeric)
{
lower = 65; higher = 123; hook = 91; jump = 97;
}
if(!alphanumeric)
{
lower = 32; higher = 126; hook = 90; jump = 92;
}
for (int i = lower; i < higher; i++)
{
alphabet.Add((char)(i));
if (i == hook)
{
i = jump;
}
}
for(int i =0; i < length; i++)
{
key += alphabet[rnd.Next(0, alphabet.Count)];
}
return key;
}
}
public class IV
{
}
}
}