2022-04-18 00:09:42 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using static System.Console;
|
|
|
|
|
using static System.Threading.Thread;
|
|
|
|
|
|
|
|
|
|
namespace cce {
|
|
|
|
|
class Transcoder {
|
|
|
|
|
static internal string result = "";
|
2022-04-22 13:50:27 +00:00
|
|
|
|
static private List<string> extended_dict = null;
|
|
|
|
|
static private List<string> common_dict = null;
|
2022-04-18 00:09:42 +00:00
|
|
|
|
static private Dictionary<char, char> substitution = new Dictionary<char, char>{
|
|
|
|
|
{'a','a' },
|
|
|
|
|
{'b','t' },
|
|
|
|
|
{'c','y' },
|
|
|
|
|
{'d','p' },
|
|
|
|
|
{'e','e' },
|
|
|
|
|
{'f','t' },
|
|
|
|
|
{'g','j' },
|
|
|
|
|
{'h','k' },
|
|
|
|
|
{'i','i' },
|
|
|
|
|
{'j','t' },
|
|
|
|
|
{'k','k' },
|
|
|
|
|
{'l','p' },
|
|
|
|
|
{'m','s' },
|
|
|
|
|
{'n','t' },
|
|
|
|
|
{'o','o' },
|
|
|
|
|
{'p','k' },
|
|
|
|
|
{'q','r' },
|
|
|
|
|
{'r','t' },
|
|
|
|
|
{'s','y' },
|
|
|
|
|
{'t','p' },
|
|
|
|
|
{'u','u' },
|
|
|
|
|
{'v','t' },
|
|
|
|
|
{'w','j' },
|
|
|
|
|
{'x','k' },
|
|
|
|
|
{'y','y' },
|
|
|
|
|
{'z','b' }
|
|
|
|
|
};
|
|
|
|
|
static private Dictionary<char, string> decode_key = new Dictionary<char, string>{
|
|
|
|
|
{'a',"a" },
|
|
|
|
|
{'t',"bfjnrv"},
|
|
|
|
|
{'y',"csy" },
|
|
|
|
|
{'p',"dlt" },
|
|
|
|
|
{'e',"e" },
|
|
|
|
|
{'j',"gw" },
|
|
|
|
|
{'k',"hkpx" },
|
|
|
|
|
{'i',"i" },
|
|
|
|
|
{'s',"m" },
|
|
|
|
|
{'o',"o" },
|
|
|
|
|
{'r',"q" },
|
|
|
|
|
{'u',"u" },
|
|
|
|
|
{'b',"z" }
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
static internal void Teacher() {
|
|
|
|
|
var pos = CursorTop;
|
|
|
|
|
Write("Please enter the encrypted word: ");
|
|
|
|
|
var cyphered = Console.ReadLine().ToLower();
|
|
|
|
|
if (cyphered == "") return;
|
|
|
|
|
CursorTop = pos;
|
|
|
|
|
string translation = "";
|
|
|
|
|
while (true) {
|
|
|
|
|
Write($"Please enter a translation for \"{cyphered}\": ");
|
|
|
|
|
translation = ReadLine().ToLower();
|
|
|
|
|
if (raw_encode(cyphered).ToLower() == cyphered) {
|
|
|
|
|
Console.BackgroundColor = ConsoleColor.Green; Console.ForegroundColor = ConsoleColor.Black;
|
|
|
|
|
WriteLine("Cypher Match!"); ResetColor(); break;
|
|
|
|
|
}
|
|
|
|
|
Console.BackgroundColor = ConsoleColor.Red;
|
|
|
|
|
WriteLine("Words don't match");
|
|
|
|
|
ResetColor();
|
|
|
|
|
}
|
|
|
|
|
var entered = false;
|
|
|
|
|
char cki;
|
|
|
|
|
do {
|
|
|
|
|
Utils.LagWrite(@"Where do you want to save the translation?
|
|
|
|
|
[1] Common words dictionary
|
|
|
|
|
[2] Extended words dictionary
|
|
|
|
|
>>> ".Replace("\r\n", "\n"));
|
|
|
|
|
cki = ReadKey().KeyChar;
|
|
|
|
|
WriteLine();
|
|
|
|
|
if (extended_dict == null || common_dict == null) init();
|
|
|
|
|
switch (cki) {
|
|
|
|
|
case '1':
|
2022-04-22 13:50:27 +00:00
|
|
|
|
if (common_dict.Contains(translation)) {
|
2022-04-18 00:09:42 +00:00
|
|
|
|
WriteLine("Error: Unable to add a new translation. Translation already present.");
|
2022-04-22 13:50:27 +00:00
|
|
|
|
} else common_dict.Add(translation);
|
2022-04-18 00:09:42 +00:00
|
|
|
|
entered = true;
|
|
|
|
|
break;
|
|
|
|
|
case '2':
|
2022-04-22 13:50:27 +00:00
|
|
|
|
if (extended_dict.Contains(translation)) {
|
2022-04-18 00:09:42 +00:00
|
|
|
|
WriteLine("Error: Unable to add a new translation. Translation already present.");
|
2022-04-22 13:50:27 +00:00
|
|
|
|
} else extended_dict.Add(translation);
|
2022-04-18 00:09:42 +00:00
|
|
|
|
entered = true;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
CursorLeft--; WriteLine("Not a valid option");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} while (!entered);
|
|
|
|
|
Console.BackgroundColor = cki == '1' ? ConsoleColor.Green : ConsoleColor.Blue; Console.ForegroundColor = ConsoleColor.Black;
|
|
|
|
|
WriteLine("Translation Added"); ResetColor();
|
|
|
|
|
update();
|
|
|
|
|
}
|
2022-04-26 13:56:42 +00:00
|
|
|
|
static internal void Encode(List<string> entry, out string encrypted) {
|
|
|
|
|
var temp = new List<string>();
|
|
|
|
|
WriteLine("Transcoding:\n{0}\n", String.Join("\n", entry));
|
|
|
|
|
for (int i = 0; i < entry.Count; i++) {
|
|
|
|
|
result = raw_encode(entry[i]);
|
|
|
|
|
Utils.LagWrite(result);
|
|
|
|
|
temp.Add(result);
|
|
|
|
|
if(entry.Count>1) WriteLine();
|
|
|
|
|
}
|
|
|
|
|
encrypted = String.Join("\n", temp);
|
|
|
|
|
}
|
|
|
|
|
static internal void Decode(List<string> lines) {
|
|
|
|
|
for (int i = 0; i < lines.Count; i++) {
|
|
|
|
|
raw_decode(lines[i]);
|
|
|
|
|
if (lines.Count <= 1 || i == lines.Count-1) break;
|
|
|
|
|
SetCursorPosition(0, WindowHeight - 2);
|
|
|
|
|
Write("Press Enter to write the next line");
|
|
|
|
|
while (true) {
|
|
|
|
|
var cki = ReadKey();
|
|
|
|
|
if (cki.Key == ConsoleKey.Enter) break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
static private void update() {
|
|
|
|
|
uniquere();
|
|
|
|
|
var dict = new Dictionary<string, List<string>>();
|
|
|
|
|
File.WriteAllText(AppSettings.Dictionary, JsonConvert.SerializeObject(dict));
|
|
|
|
|
}
|
|
|
|
|
static private string raw_encode(string entry) {
|
|
|
|
|
var sentence = entry.ToLower();
|
|
|
|
|
char[] encoded = new char[entry.Length];
|
|
|
|
|
for (int i = 0; i < sentence.Length; i++) {
|
|
|
|
|
if (substitution.TryGetValue(sentence[i], out char substituted)) {
|
|
|
|
|
encoded[i] = Char.IsUpper(entry[i]) ? Char.ToUpper(substituted) : Char.ToLower(substituted);
|
|
|
|
|
} else {
|
|
|
|
|
encoded[i] = entry[i];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return String.Join("", encoded);
|
2022-04-18 00:09:42 +00:00
|
|
|
|
}
|
2022-04-26 13:56:42 +00:00
|
|
|
|
static private void raw_decode(string entry) {
|
2022-04-18 00:09:42 +00:00
|
|
|
|
var sentence = entry.ToLower();
|
|
|
|
|
//120x30, buffer 240x60
|
|
|
|
|
if (sentence.Length >= 120) { BufferWidth = sentence.Length * 2; WindowWidth = sentence.Length + 20; }
|
|
|
|
|
Clear();
|
|
|
|
|
CursorVisible = false;
|
2022-04-19 13:02:35 +00:00
|
|
|
|
var checker = init();
|
|
|
|
|
if (!checker) {
|
|
|
|
|
WriteLine("Unable to load dictionaries");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-04-18 00:09:42 +00:00
|
|
|
|
var cleaned = new char[sentence.Length];
|
|
|
|
|
var symbols = new char[sentence.Length];
|
|
|
|
|
var writeout = new char[sentence.Length];
|
|
|
|
|
for (int i = 0; i < sentence.Length; i++) {
|
|
|
|
|
if (sentence[i] >= 'a' && sentence[i] <= 'z') { cleaned[i] = sentence[i]; symbols[i] = 'x'; writeout[i] = '_'; } else { writeout[i] = symbols[i] = sentence[i]; cleaned[i] = ' '; }
|
|
|
|
|
}
|
|
|
|
|
var decode = string.Join("", cleaned).ToLower().Split(' ');
|
|
|
|
|
//var decoded = new List<List<string>>();
|
|
|
|
|
Console.BackgroundColor = ConsoleColor.Green;
|
|
|
|
|
Console.Write(" "); ResetColor(); Console.WriteLine(" Frequent Words");
|
|
|
|
|
Console.BackgroundColor = ConsoleColor.Blue;
|
|
|
|
|
Console.Write(" "); ResetColor(); Console.WriteLine(" Infrequent Words");
|
|
|
|
|
Console.BackgroundColor = ConsoleColor.Red;
|
|
|
|
|
Console.Write(" "); ResetColor(); Console.WriteLine(" Letter decypher");
|
|
|
|
|
WriteLine("Transcoding:\n{0}\n", entry);
|
|
|
|
|
int memTop = CursorTop;
|
|
|
|
|
int left = 0;
|
|
|
|
|
Write(string.Join("", writeout));
|
|
|
|
|
for (int i = 0; i < decode.Length; i++) {
|
|
|
|
|
if (symbols[left] != 'x') left++;
|
|
|
|
|
CursorTop = memTop;
|
|
|
|
|
Console.BackgroundColor = ConsoleColor.Green;
|
|
|
|
|
Console.ForegroundColor = ConsoleColor.Black;
|
2022-04-22 13:50:27 +00:00
|
|
|
|
wordwrite(common_dict, decode[i], entry, left);
|
2022-04-18 00:09:42 +00:00
|
|
|
|
Console.BackgroundColor = ConsoleColor.Blue;
|
2022-04-22 13:50:27 +00:00
|
|
|
|
wordwrite(extended_dict, decode[i], entry, left);
|
2022-04-18 00:09:42 +00:00
|
|
|
|
ResetColor();
|
|
|
|
|
List<List<char>> letter_decode = new List<List<char>>();
|
|
|
|
|
for (int j = 0; j < decode[i].Length; j++) {
|
|
|
|
|
if (decode_key.TryGetValue(decode[i][j], out string substituted)) {
|
|
|
|
|
var letterlist = new List<char>();
|
|
|
|
|
for (int h = 0; h < substituted.Length; h++) {
|
|
|
|
|
letterlist.Add(substituted[h]);
|
|
|
|
|
}
|
|
|
|
|
letter_decode.Add(letterlist);
|
2022-04-26 13:56:42 +00:00
|
|
|
|
}
|
|
|
|
|
else {
|
2022-04-18 00:09:42 +00:00
|
|
|
|
letter_decode.Add(new List<char> { sentence[j] });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
int top = CursorTop;
|
|
|
|
|
int letterleft = left;
|
|
|
|
|
Console.BackgroundColor = ConsoleColor.Red;
|
|
|
|
|
Console.ForegroundColor = ConsoleColor.Black;
|
|
|
|
|
for (int j = 0; j < letter_decode.Count; j++) {
|
|
|
|
|
for (int h = 0; h < letter_decode[j].Count; h++) {
|
|
|
|
|
CursorLeft = letterleft;
|
|
|
|
|
Write(Char.IsUpper(entry[CursorLeft]) ? Char.ToUpper(letter_decode[j][h]) : Char.ToLower(letter_decode[j][h]));
|
|
|
|
|
Sleep(10);
|
|
|
|
|
CursorTop++;
|
|
|
|
|
}
|
|
|
|
|
CursorTop = top;
|
|
|
|
|
letterleft++;
|
|
|
|
|
}
|
|
|
|
|
Sleep(80);
|
|
|
|
|
left += decode[i].Length;
|
|
|
|
|
}
|
|
|
|
|
ResetColor();
|
|
|
|
|
//return string.Join(" ", decoded);
|
|
|
|
|
}
|
2022-04-19 13:02:35 +00:00
|
|
|
|
static internal bool init() {
|
|
|
|
|
if (common_dict != null && extended_dict != null) return true;
|
|
|
|
|
var checker = true;
|
2022-04-22 13:50:27 +00:00
|
|
|
|
var dict = new Dictionary<string, List<string>>();
|
2022-04-18 00:09:42 +00:00
|
|
|
|
WriteLine("[Loading Dictionary]");
|
2022-04-22 13:50:27 +00:00
|
|
|
|
if (File.Exists(AppSettings.Dictionary)) dict = JsonConvert.DeserializeObject<Dictionary<string, List<string>>>(File.ReadAllText(AppSettings.Dictionary));
|
2022-04-19 13:02:35 +00:00
|
|
|
|
else { WriteLine("File missing"); checker = false; }
|
2022-04-22 13:50:27 +00:00
|
|
|
|
common_dict = dict["common"];
|
|
|
|
|
extended_dict = dict["extended"];
|
2022-04-19 13:02:35 +00:00
|
|
|
|
return checker;
|
2022-04-18 00:09:42 +00:00
|
|
|
|
}
|
2022-04-22 13:50:27 +00:00
|
|
|
|
static private void uniquere() {
|
2022-04-18 00:09:42 +00:00
|
|
|
|
init();
|
|
|
|
|
foreach (var item in common_dict) {
|
2022-04-22 13:50:27 +00:00
|
|
|
|
if (extended_dict.Contains(item)) extended_dict.Remove(item);
|
2022-04-18 00:09:42 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-04-22 13:50:27 +00:00
|
|
|
|
static private void wordwrite(List<string> collection, string decode, string entry,int left) {
|
2022-04-18 00:09:42 +00:00
|
|
|
|
foreach (var item in collection) {
|
2022-04-22 13:50:27 +00:00
|
|
|
|
var trans = raw_encode(item);
|
|
|
|
|
if (trans == decode) {
|
2022-04-18 00:09:42 +00:00
|
|
|
|
CursorLeft = left;
|
|
|
|
|
//options.Add(item.Key);
|
2022-04-22 13:50:27 +00:00
|
|
|
|
for (int j = 0; j < item.Length; j++) {
|
|
|
|
|
Write(Char.IsUpper(entry[CursorLeft]) ? Char.ToUpper(item[j]) : Char.ToLower(item[j]));
|
2022-04-18 00:09:42 +00:00
|
|
|
|
}
|
|
|
|
|
Utils.VarSleep(10, low: 20,high:100);
|
|
|
|
|
CursorTop++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|