Corpus-Cypher-Executable/cce/Program.cs

151 lines
5.6 KiB
C#
Raw Permalink Normal View History

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 Program {
static internal string title = "Corpus Cypher Executable (CCE)";
2022-04-18 14:53:21 +00:00
[STAThread]
2022-04-18 00:09:42 +00:00
static void Main(string[] args) {
byte choice = 255;
2022-04-18 22:21:06 +00:00
AppSettings.Update();
2022-04-18 00:09:42 +00:00
while (true) {
2022-04-19 12:42:29 +00:00
Title = title;
2022-04-18 00:09:42 +00:00
SetBufferSize(240, 60);
SetWindowSize(120, 30);
Clear();
CursorVisible = false;
Utils.LagWrite("Welcome to the " + title, true);
//WriteLine("Welcome to the Corpus cypher executable.");
WriteCrypto();
2022-04-18 22:21:06 +00:00
choice = Chooser();
2022-04-18 00:09:42 +00:00
CursorVisible = false;
var entry = "";
if ((new int[] {1,2}).Contains(choice)) {
Utils.LagWrite("Please enter the sentence: ");
CursorVisible = true;
//Write("Please enter the sentence: ");
entry = ReadLine();
CursorVisible = false;
}
2022-04-18 22:21:06 +00:00
bool skip = false;
2022-04-18 00:09:42 +00:00
if (choice == 1) { Transcoder.Encode(entry); Utils.Clip(Transcoder.result); }
else if (choice == 2) Transcoder.Decode(entry);
else if (choice == 5) Transcoder.Teacher();
2022-04-18 22:21:06 +00:00
else if (choice == 8) skip = App.Settings();
2022-04-18 00:09:42 +00:00
else if (choice == 9) Transcoder.head_transcribe();
2022-04-18 22:21:06 +00:00
else if (choice == 254) Help();
else if (choice == 255) { Beep(4000, 200); return; }
2022-04-18 00:09:42 +00:00
SetCursorPosition(0, WindowHeight - 2);
2022-04-18 22:21:06 +00:00
if (!skip) {
Utils.LagWrite("\nPress enter to continue, press any other key to exit"); CursorVisible = false;
var cki = ReadKey();
if (cki.Key != ConsoleKey.Enter) break;
}
2022-04-18 00:09:42 +00:00
}
}
static byte Chooser() {
while (true) {
Utils.LagWrite("[1] Encode"
+"\n[2] Decode"
+"\n-------------------------"
+"\n[5] Teach new words"
+"\n-------------------------"
2022-04-18 14:53:21 +00:00
+"\n[8] Settings"
2022-04-18 00:09:42 +00:00
+"\n[9] DEV: Update JSON files using sorted files from python"
2022-04-18 14:53:21 +00:00
+"\n[?] Help"
2022-04-18 22:21:06 +00:00
+"\n[Backspace] Exit"
2022-04-18 00:09:42 +00:00
+"\n>>> ");
/*Write(@"Options?
[1] Encode
[2] Decode
-------------------------
[5] Teach new words
-------------------------
[9] DEV: Update JSON files using sorted files from python
[0] Exit
>> ");*/
CursorVisible = true;
2022-04-18 22:21:06 +00:00
var choice = ReadKey();
2022-04-18 00:09:42 +00:00
WriteLine();
2022-04-18 22:21:06 +00:00
if (choice.Key == ConsoleKey.Backspace) return 255;
switch (choice.KeyChar) {
2022-04-18 00:09:42 +00:00
case '1':
case '2':
case '5':
case '9':
2022-04-18 14:53:21 +00:00
case '8':
2022-04-18 00:09:42 +00:00
case '0':
case '?':
case '/':
case '-':
case ',':
2022-04-18 22:21:06 +00:00
if ((new char[] { '?','/','-',','}).Contains(choice.KeyChar)) return 254;
return byte.Parse(choice.KeyChar.ToString());
2022-04-18 00:09:42 +00:00
default:
WriteLine("Not a valid option");
break;
}
}
}
static void WriteCrypto()
{
var pos = (CursorLeft, CursorTop);
var crypto = new string[] {"###########################",
"# #",
"# Corpus Cypher #",
"# #",
"###########################",
"# ENG = COR #",
"# A = A G = J M = S #",
"# B = T H = K N = T #",
"# C = Y I = I O = O #",
"# D = P J = T P = K #",
"# E = E K = K Q = R #",
"# F = T L = P R = T #",
"# #",
"# S = Y W = J #",
"# T = P X = K #",
"# U = U Y = Y #",
"# V = T Z = B #",
"# #",
"###########################"};
for (int i = 0; i < crypto.Length; i++)
{
CursorTop = i + 2;
CursorLeft = WindowWidth - crypto[i].Length - 2;
foreach (char c in crypto[i]) {
Write(c);
2022-04-18 22:21:06 +00:00
if (AppSettings.Lgwrite == 1 && Utils.rng.NextDouble()>0.8 && c != ' ') Sleep(1);
2022-04-18 00:09:42 +00:00
}
}
SetCursorPosition(pos.CursorLeft, pos.CursorTop);
}
static void Help() {
Clear();
var help = $@"Welcome to help for {title}
This executable was made to help you encrypt something into the Corpus Cypher
and to give you idea of what the person on the other end was trying to say.
This executable isn't fool proof and some mistakes in the code might've slipped
through my fingers. Still I hope it is atleast somewhat useful.
Encoding: Encoded text takes on the capitalization of the entered text.
Decoding: Decoded text takes on the capitalization of the entered text.
Teaching: First you enter in the encrypted word and then you give it the translation. It will remember the word.";
help = help.Replace("\r\n", "\n");
Utils.LagWrite(help);
}
}
}