/// <summary> /// Encrypts or decrypts text using the current Enigma machine. /// </summary> public void StartCipher() { Debug.LogMethodStart(); string type; FileInput inputFile; if (IsDecrypting) { type = "Decrypt"; } else { type = "Encrypt"; } ConsoleOutput.IndentWriteLine($"Now starting {type.ToLower()}ion with Enigma Machine: {Current.Name}"); ConsoleOutput.ContinuePrompt(); string toCipher = ""; switch (InputType) { case InputType.html: inputFile = new FileInput(FileIn + ".html"); toCipher = Utility.HtmlToText(inputFile.Read()); break; case InputType.txt: inputFile = new FileInput(FileIn + ".txt"); toCipher = inputFile.Read(); break; case InputType.keyboard: toCipher = UserInput.GetStringFromUser($"Enter text to be {type.ToLower()}ed"); inputFile = null; break; default: InputType = InputType.keyboard; inputFile = null; StartCipher(); break; } if (toCipher?.Length > 0) { Debug.Log(false, $"INPUT:\n {toCipher}"); var outputFile = new FileOutput(FileOut); var builder = new StringBuilder(); string output = Cipher(toCipher.ToCharArray(), inputFile); builder.Append(Utility.TextToHtml(output, $"{type}ion output from Enigma Machine: {Current.Name}")); outputFile.Write(builder, ($"Wrote {type.ToLower()}ed output to file {outputFile.Path}.")); ConsoleOutput.IndentWriteLine($"{type}ion complete. Resetting {Current.Name}'s rotors to initial settings."); } else { ConsoleOutput.IndentWriteLine($"Error: could not find anything to {type.ToLower()}"); } ConsoleOutput.ContinuePrompt(); }