Compare commits

..

3 commits

Author SHA1 Message Date
Helio e4ff99c68f Added last functional release 2022-04-26 16:00:10 +02:00
Helio 43675af036 Fixed Multiline entry and written Multiline output 2022-04-26 15:56:42 +02:00
Helio da0def2486 changing the files 2022-04-22 15:50:27 +02:00
21 changed files with 489316 additions and 111 deletions

View file

@ -18,7 +18,7 @@ namespace cce {
byte reset = 0;
(int, int) since = (0,0);
while (true) {
Title = Title + " >>> Settings";
Title = Program.title + " >>> Settings";
if (since.Item1 >= 4) {
saved = false;
since.Item1 = 0;
@ -56,11 +56,22 @@ namespace cce {
since.Item2++;
}
}
static internal void Dev() {
if (!File.Exists("dev")) {
BackgroundColor = ConsoleColor.Red;
WriteLine(" \n" +
" Unable to comply, not a dev \n" +
" ");
ResetColor();
return;
}
}
}
internal class AppSettings {
static internal byte Lgwrite = 1;
static internal string Common = "common.json";
static internal string Extended = "extended.json";
static internal string Dictionary = "dictionary.json";
static internal string Settings = "settings.json";
static internal (int, int) top_bottom = (0, 0);
static internal void Check() {

View file

@ -27,20 +27,21 @@ namespace cce {
WriteCrypto();
choice = Chooser();
CursorVisible = false;
var entry = "";
var entry = new List<string>();
if ((new int[] {1,2}).Contains(choice)) {
Utils.LagWrite("Please enter the sentence: ");
Utils.LagWrite("Please enter the sentence (Enter to submit, Ctrl+Enter for another line):", true);
CursorVisible = true;
//Write("Please enter the sentence: ");
entry = ReadLine();
entry = Utils.Entry();
CursorVisible = false;
}
bool skip = false;
if (choice == 1) { Transcoder.Encode(entry); Utils.Clip(Transcoder.result); }
if (choice == 1) { Transcoder.Encode(entry, out string enc); Utils.Clip(enc); }
else if (choice == 2) Transcoder.Decode(entry);
else if (choice == 5) Transcoder.Teacher();
else if (choice == 8) skip = App.Settings();
else if (choice == 9) Transcoder.head_transcribe();
else if (choice == 9) App.Dev();
else if (choice == 253) { Clear(); continue; }
else if (choice == 254) Help();
else if (choice == 255) { Beep(4000, 200); return; }
@ -61,7 +62,8 @@ namespace cce {
+"\n[5] Teach new words"
+"\n-------------------------"
+"\n[8] Settings"
+"\n[9] DEV: Update JSON files using sorted files from python"
+"\n[9] DEV"
+"\n[c] Clear Console"
+"\n[?] Help"
+"\n[Backspace] Exit"
+"\n>>> ");
@ -91,6 +93,10 @@ namespace cce {
case ',':
if ((new char[] { '?','/','-',','}).Contains(choice.KeyChar)) return 254;
return byte.Parse(choice.KeyChar.ToString());
case 'c':
case 'C':
if ((new char[] { 'c', 'C' }).Contains(choice.KeyChar)) return 253;
return byte.Parse(choice.KeyChar.ToString());
default:
WriteLine("Not a valid option");
break;

View file

@ -12,8 +12,8 @@ using static System.Threading.Thread;
namespace cce {
class Transcoder {
static internal string result = "";
static private Dictionary<string, string> extended_dict = null;
static private Dictionary<string, string> common_dict = null;
static private List<string> extended_dict = null;
static private List<string> common_dict = null;
static private Dictionary<char, char> substitution = new Dictionary<char, char>{
{'a','a' },
{'b','t' },
@ -88,15 +88,15 @@ namespace cce {
if (extended_dict == null || common_dict == null) init();
switch (cki) {
case '1':
if (common_dict.ContainsKey(translation)) {
if (common_dict.Contains(translation)) {
WriteLine("Error: Unable to add a new translation. Translation already present.");
} else common_dict.Add(translation, cyphered);
} else common_dict.Add(translation);
entered = true;
break;
case '2':
if (extended_dict.ContainsKey(translation)) {
if (extended_dict.Contains(translation)) {
WriteLine("Error: Unable to add a new translation. Translation already present.");
} else extended_dict.Add(translation, cyphered);
} else extended_dict.Add(translation);
entered = true;
break;
default:
@ -108,12 +108,47 @@ namespace cce {
WriteLine("Translation Added"); ResetColor();
update();
}
static internal void Encode(string entry) {
result = raw_encode(entry);
WriteLine("Transcoding:\n{0}\n", entry);
Utils.LagWrite(result);
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(string entry) {
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);
}
static private void raw_decode(string entry) {
var sentence = entry.ToLower();
//120x30, buffer 240x60
if (sentence.Length >= 120) { BufferWidth = sentence.Length * 2; WindowWidth = sentence.Length + 20; }
@ -144,26 +179,12 @@ namespace cce {
Write(string.Join("", writeout));
for (int i = 0; i < decode.Length; i++) {
if (symbols[left] != 'x') left++;
//var options = new List<string>();
CursorTop = memTop;
Console.BackgroundColor = ConsoleColor.Green;
Console.ForegroundColor = ConsoleColor.Black;
wordwrite(common_dict, decode[i], entry, left, i);
/*foreach (var item in common_dict) {
if (item.Value == decode[i]) {
CursorLeft = left;
//options.Add(item.Key);
for (int j = 0; j < item.Key.Length; j++) {
Write(Char.IsUpper(entry[i]) ? char.Parse(item.Key[j].ToString().ToUpper()) : char.Parse(item.Key[j].ToString().ToLower()));
}
Write(item.Key.ToUpper());
Sleep(100);
CursorTop++;
}
}*/
wordwrite(common_dict, decode[i], entry, left);
Console.BackgroundColor = ConsoleColor.Blue;
Console.ForegroundColor = ConsoleColor.Black;
wordwrite(extended_dict, decode[i], entry, left, i);
wordwrite(extended_dict, decode[i], entry, left);
ResetColor();
List<List<char>> letter_decode = new List<List<char>>();
for (int j = 0; j < decode[i].Length; j++) {
@ -173,7 +194,8 @@ namespace cce {
letterlist.Add(substituted[h]);
}
letter_decode.Add(letterlist);
} else {
}
else {
letter_decode.Add(new List<char> { sentence[j] });
}
}
@ -197,95 +219,31 @@ namespace cce {
ResetColor();
//return string.Join(" ", decoded);
}
static internal void head_transcribe() {
if(!File.Exists("dev")) {
Clear();
BackgroundColor = ConsoleColor.Red;
Utils.LagWrite(" \n" +
" Unable to comply. Not a dev version \n"+
" ", true);
ResetColor();
return;
}
raw_transcribe("common_dict.txt", "common_dict.json");
raw_transcribe("extended_dict.txt", "extended_dict.json");
uniquire();
}
static private void update() {
uniquire();
File.WriteAllText(AppSettings.Extended, JsonConvert.SerializeObject(extended_dict));
File.WriteAllText(AppSettings.Common, JsonConvert.SerializeObject(common_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);
}
static internal bool init() {
if (common_dict != null && extended_dict != null) return true;
var checker = true;
var dict = new Dictionary<string, List<string>>();
WriteLine("[Loading Dictionary]");
if (File.Exists(AppSettings.Extended)) extended_dict = JsonConvert.DeserializeObject<Dictionary<string, string>>(File.ReadAllText(AppSettings.Extended));
else { WriteLine("File missing"); checker = false; }
if (File.Exists(AppSettings.Common)) common_dict = JsonConvert.DeserializeObject<Dictionary<string, string>>(File.ReadAllText(AppSettings.Common));
if (File.Exists(AppSettings.Dictionary)) dict = JsonConvert.DeserializeObject<Dictionary<string, List<string>>>(File.ReadAllText(AppSettings.Dictionary));
else { WriteLine("File missing"); checker = false; }
common_dict = dict["common"];
extended_dict = dict["extended"];
return checker;
}
static private void uniquire() {
static private void uniquere() {
init();
foreach (var item in common_dict) {
if (extended_dict.ContainsKey(item.Key)) extended_dict.Remove(item.Key);
if (extended_dict.Contains(item)) extended_dict.Remove(item);
}
}
static private void raw_transcribe(string input, string output) {
var lines = File.ReadAllLines(input);
for (int i = 0; i < lines.Length; i++) {
lines[i] = lines[i].ToLower();
}
var English = new string[lines.Length];
lines.CopyTo(English, 0);
for (int i = 0; i < English.Length; i++) {
var word = new char[English[i].Length];
for (int j = 0; j < English[i].Length; j++) {
if (substitution.TryGetValue(English[i][j], out char substituted)) {
word[j] = substituted;
}
else {
word[j] = English[i][j];
}
}
lines[i] = String.Join("", word);
WriteLine($"{English[i]}:{lines[i]}");
}
Dictionary<string, string> vals = new Dictionary<string, string>();
for (int i = 0; i < English.Length; i++) {
if (vals.ContainsKey(English[i])) continue;
vals.Add(English[i], lines[i]);
}
File.WriteAllText(output, JsonConvert.SerializeObject(vals));
}
static internal void concat() {
init();
var dict = new Dictionary<string, Dictionary<string, string>>();
dict.Add("short", common_dict);
dict.Add("long", extended_dict);
File.WriteAllText("dictionary.json", JsonConvert.SerializeObject(dict));
}
static private void wordwrite(Dictionary<string, string> collection, string decode, string entry,int left, int i) {
static private void wordwrite(List<string> collection, string decode, string entry,int left) {
foreach (var item in collection) {
if (item.Value == decode) {
var trans = raw_encode(item);
if (trans == decode) {
CursorLeft = left;
//options.Add(item.Key);
for (int j = 0; j < item.Key.Length; j++) {
Write(Char.IsUpper(entry[CursorLeft]) ? Char.ToUpper(item.Key[j]) : Char.ToLower(item.Key[j]));
for (int j = 0; j < item.Length; j++) {
Write(Char.IsUpper(entry[CursorLeft]) ? Char.ToUpper(item[j]) : Char.ToLower(item[j]));
}
Utils.VarSleep(10, low: 20,high:100);
CursorTop++;

View file

@ -27,7 +27,7 @@ namespace cce {
WriteLine();
if (Char.ToLower(cki) == 'y') { Clipboard.SetText(clip); WriteLine("Writing to Clipboard: Done!"); } else WriteLine("Writing to Clipboard: Canceled by User");
}
internal static void LagWrite(string input, bool newline = false) {
static internal void LagWrite(string input, bool newline = false) {
if (AppSettings.Lgwrite == 0) {
if (newline) WriteLine(input);
else Write(input);
@ -59,5 +59,40 @@ namespace cce {
if (newline || i < phrases.Count - 1) WriteLine();
}
}
static internal List<string> Entry() {
var list = new List<string>();
ConsoleKeyInfo input = new ConsoleKeyInfo();
bool exit = false;
do {
List<char> chars = new List<char>();
exit = false;
for (int i = 0; i < 30; i++) {
input = ReadKey();
if (chars.Count > 0 && input.Key == ConsoleKey.Enter && input.Modifiers == ConsoleModifiers.Control) {
list.Add(String.Join("", chars));
break;
}
else if (i > 20 && input.Key == ConsoleKey.Spacebar || i > 29) {
list.Add(String.Join("", chars));
WriteLine();
break;
}
else if (chars.Count > 0 && input.Key == ConsoleKey.Enter && input.Modifiers == 0) {
list.Add(String.Join("", chars));
exit = true;
break;
}
else if (input.Key == ConsoleKey.Backspace) {
chars.RemoveAt(chars.Count-1);
if (CursorLeft >0) {
Write(" "); CursorLeft--;
}
}
else chars.Add(input.KeyChar);
}
} while (!exit);
return list;
}
}
}

File diff suppressed because it is too large Load diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,26 @@
import json
f1 = open('common.json', 'r')
f2 = open('extended.json', 'r')
data1 = json.load(f1)
data2 = json.load(f2)
f1.close()
f2.close()
words1 = []
words2 = []
for key in data1:
words1.append(key)
for key in data2:
words2.append(key)
dict = {
'common':words1,
'extended':words2
}
f = open("dictionary.json", "w")
json.dump(dict, f)
f.close()
print("done")

1
cce/strip.py Normal file
View file

@ -0,0 +1 @@
import json

Binary file not shown.

File diff suppressed because it is too large Load diff

Binary file not shown.

File diff suppressed because one or more lines are too long

Binary file not shown.

File diff suppressed because it is too large Load diff

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1 @@
{"LagWrite":"1","Common":"common.json","Extended":"extended.json","Settings":"settings.json"}

Binary file not shown.