static void Main(string[] args) { Random myRand = new Random(); Enigma myCode = new Enigma(myRand); int userChoice; string userMessage; do { Console.Write("Enter '1' to Encrypt a message, '2' to Decrypt a message, or '0' to Exit: "); userChoice = Int32.Parse(Console.ReadLine()); switch (userChoice) { case 1: Console.WriteLine("\nWhat message would you like to encrypt?\n"); userMessage = Console.ReadLine().ToUpper(); Console.WriteLine(myCode.Encrypt(userMessage)); Console.WriteLine(); break; case 2: Console.WriteLine("\nWhat message would you like to decrypt?\n"); userMessage = Console.ReadLine().ToUpper(); Console.WriteLine(myCode.Decrypt(userMessage)); Console.WriteLine(); break; default: break; } } while (userChoice != 0); }
private async Task HandleInputChange(string oldValue, string newValue) { await _semaphoreQueue.WaitAsync(); await Task.Run(async() => { if (oldValue.Length < newValue.Length) { var addedSubstring = newValue.Substring(oldValue.Length); addedSubstring = addedSubstring.ToUpper(); foreach (var c in addedSubstring) { var x = c; if (char.IsLetter(c)) { x = await Enigma.Encrypt(c); } Output += x; } } else if (oldValue.Length > newValue.Length) { Output = Output.Remove(newValue.Length); } }); _semaphoreQueue.Release(); }
public void Encrypt(string plaintext, string ciphertext, char newFastestRotorPosition) { IEnigmaSettings settings = new EnigmaSettings(); ICipher cipher = new Enigma(settings); Assert.Equal(ciphertext, cipher.Encrypt(plaintext)); Assert.Equal(newFastestRotorPosition, settings.Rotors[EnigmaRotorPosition.Fastest].CurrentSetting); }
public void TestEncryption(string message, string encrypt) { // 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 var encrypted = Enigma.Encrypt(message); Assert.AreEqual(encrypt, encrypted); }
static void Main(string[] args) { while (true) { Console.Clear(); Console.ForegroundColor = ConsoleColor.White; WriteColored("Welcome to Enigma Encryption\n\n", ConsoleColor.Green); WriteColored("Please enter your password: "******"Enter your input text: "); Console.ForegroundColor = ConsoleColor.Blue; var plainText = Console.ReadLine(); var enigma = new Enigma(pass?.Length ?? 3); var cipher = enigma.Encrypt(plainText, pass); WriteColored(cipher, ConsoleColor.DarkMagenta); Console.ReadLine(); } }
public async void Encrypt_ShouldReturnCharacter(char input, char expected) { // Arrange var eventAggregator = new EventAggregator(); var utilityFactory = new UtilityFactory(); var componentFactory = new ComponentFactory(utilityFactory); var settings = new EnigmaSettingsStub(eventAggregator, componentFactory); var savedSettings = new EnigmaSettings.SavedSettings() { ReflectorType = ReflectorType.B, PlugboardConnections = new Dictionary <char, char>(), Slot1 = new EnigmaSettings.SavedSettings.Slot() { Position = 6, RotorType = RotorType.II, }, Slot2 = new EnigmaSettings.SavedSettings.Slot() { Position = 11, RotorType = RotorType.I, }, Slot3 = new EnigmaSettings.SavedSettings.Slot() { Position = 5, RotorType = RotorType.III, }, }; settings.LoadSettings(savedSettings); var enigma = new Enigma(settings, utilityFactory); // Act var result = await enigma.Encrypt(input); // Assert Assert.Equal(expected, result); }
public static string ToRijndael(this string plainText) { return(Enigma.Encrypt(plainText)); }