private string[] PromptForBytes(string initialMessage) { while (true) { ForeverHeader.Clear(); Console.WriteLine(initialMessage); string temp = Console.ReadLine(); if (temp.Length != 32) { Console.WriteLine("The key has to be 16 bytes - aka 32 characters symbolising 16 hexadecimal bytes"); Console.WriteLine(PressAnyKey); Console.ReadKey(true); continue; } string[] tempArray = temp.Chunk(2).Select(x => new string(x.ToArray())).ToArray(); if (tempArray.Any(x => !isHexadecimalByteRepresentation(x))) { Console.WriteLine("One/some of the bytes are not in a correct hexadecimal form - eg. \"FF\""); Console.WriteLine(PressAnyKey); Console.ReadKey(true); continue; } return(tempArray); } }
public Tuple <string[], string[]> InputValues() { string[] userDefinedKey = PromptForBytes("Specify the AES key as hex byte representations (Without whitespace):"); string[] userDefinedInputBytes = PromptForBytes("Specify the input bytes as hex representations (Without whitespace):"); ForeverHeader.Clear(); return(new Tuple <string[], string[]>(userDefinedKey, userDefinedInputBytes)); }
private int PromptAndValidateUserForANumber(Action WriteInstructions, Array choiceEnumeration, Func <int, Array, int> enumerationIndexRetrieval) { ForeverHeader.Clear(); WriteInstructions(); int selectedCommand = 0; while (true) { ConsoleKeyInfo keyRead = Console.ReadKey(true); if (!int.TryParse(keyRead.KeyChar.ToString(), out selectedCommand)) { ForeverHeader.Clear(); WriteInstructions(); Console.WriteLine("You should try pressing a number"); continue; } IEnumerable <int> allowedCommands = (choiceEnumeration.Cast <object>()).Select((x, index) => enumerationIndexRetrieval(index, choiceEnumeration)); if (!allowedCommands.Contains(selectedCommand)) { StringBuilder builder = new StringBuilder(); builder.Append("You can only choose between the numbers "); foreach (int commandIndex in allowedCommands) { builder.Append($"{commandIndex}, "); } ForeverHeader.Clear(); WriteInstructions(); Console.WriteLine(builder.ToString()); continue; } else { break; } } ForeverHeader.Clear(); return(selectedCommand); }
public void PromptForContinue() { Console.WriteLine(PressAnyKey); Console.ReadKey(true); ForeverHeader.Clear(); }