-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
94 lines (88 loc) · 3.38 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
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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
namespace Flawless2
{
class Program
{
public static Random rng = new Random();
public static char[] inputAlpha = new char[] { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
static void Main(string[] args)
{
Console.WriteLine("Welcome to *F L A W L E S S* v2.0");
Console.Write("Insert what you'd want to encode or decode:");
string toEncrypt = Console.ReadLine();
Console.Write("Insert the key (any string. empty for default, \"gen\" to generate):");
string key = Console.ReadLine().Replace(" ", "");
key = key.Length < 1 ? "flawless" : key;
if (key == "gen")
{
string newKey = "";
while (newKey.Length != 32)
{
char pass = inputAlpha[rng.Next(0, inputAlpha.Length)];
newKey += pass;
}
key = newKey;
Console.WriteLine("Your generated key: " + newKey);
}
var flawless = new FlawlessAlgo();
flawless.InitialKey = key;
//figuring out if we should encrypt or decrypt
byte[] data = new byte[] { };
bool doWeEncrypt = true;
try
{
byte[] encBytes = Convert.FromBase64String(toEncrypt);
if (FlawlessAlgo.IsEncrypted(encBytes))
{
Console.Write("We've detected encrypted contents! Do you wish to encrypt them (1) or decrypt them? (2):");
string choice = Console.ReadLine();
doWeEncrypt = choice != "2";
}
}
catch { doWeEncrypt = true; }
if (!doWeEncrypt) //decoding
{
//extract the data from base64 string
byte[] contents = Convert.FromBase64String(toEncrypt);
byte[] decrypted = flawless.Decrypt(contents).ToArray();
string str = Encoding.UTF8.GetString(decrypted);
Console.WriteLine($"Your output:{str}");
}
else //encoding
{
byte[] encResult = flawless.Encrypt(Encoding.UTF8.GetBytes(toEncrypt)).ToArray();
string base64 = Convert.ToBase64String(encResult);
Console.WriteLine($"Your output:{base64}");
}
}
public static bool bacmp(byte[] a1, byte[] a2)
{
if (a1 == a2)
{
return true;
}
if ((a1 != null) && (a2 != null))
{
if (a1.Length != a2.Length)
{
return false;
}
for (int i = 0; i < a1.Length; i++)
{
if (a1[i] != a2[i])
{
return false;
}
}
return true;
}
return false;
}
}
}