-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
46 lines (40 loc) · 1.35 KB
/
Program.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
using Lolcat;
namespace CifraVernam
{
class Program
{
static RainbowStyle style = new RainbowStyle();
static Rainbow rainbow = new Rainbow(style);
static void Main(string[] args)
{
string key = RandomKey(10);
string vernam = "";
string text = "Ola Mundo!";
string key = RandomKey(text.Length);
for (int i = 0; i < text.Length; i++)
{
vernam += (char)(text[i] ^ key[i]);
}
rainbow.WriteLineWithMarkup($"Chave: {key}");
rainbow.WriteLineWithMarkup($"Texto encriptado: {ToHex(vernam)}");
}
static string ToHex(string input)
{
char[] chars = input.ToCharArray();
string hexOutput = "";
foreach (char c in chars)
{
hexOutput += ((int)c).ToString("X2");
}
return hexOutput;
}
static string RandomKey(int length)
{
string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
var random = new Random();
string password = new string(Enumerable.Repeat(chars, length)
.Select(s => s[random.Next(s.Length)]).ToArray());
return password;
}
}
}