static void Main(string[] args) { ProgramMenu menu = new ProgramMenu(); Tuple <string[], string[]> lastCipherText = null; while (true) { ProgramAction direction = menu.ChooseCipherAction(); AesCipher cipherProgram = new AesCipher(); Tuple <string[], string[]> valuesToUse = null; while (valuesToUse == null) { switch (direction) { case ProgramAction.Cipher: { CipherInputAction menuStartingChoice = menu.ChooseCipherInputType(); valuesToUse = GetCipherProgramValuesToUse(menu, menuStartingChoice); IEnumerable <RoundWords> roundKeys = GetRoundKeys(valuesToUse); menu.PromptForContinue(); byte[] inputBytes = valuesToUse.Item2.Select(x => CreateByteFromHexadecimal(x)).ToArray(); ByteArray result = cipherProgram.Cipher(inputBytes, roundKeys); lastCipherText = new Tuple <string[], string[]>(valuesToUse.Item1, result.Bytes1dArray.Select(x => CreateHexadecimalFromByte(x)).ToArray()); break; } case ProgramAction.Decipher: { DecipherInputAction menuStartingChoice = menu.ChooseDecipherInputType(); valuesToUse = GetDecipherProgramValuesToUse(menu, menuStartingChoice, lastCipherText); IEnumerable <RoundWords> roundKeys = GetRoundKeys(valuesToUse); menu.PromptForContinue(); byte[] inputBytes = valuesToUse.Item2.Select(x => CreateByteFromHexadecimal(x)).ToArray(); cipherProgram.Decipher(inputBytes, roundKeys); break; } default: { throw new Exception(SurpriseExceptionMessage); } } } menu.PromptForContinue(); } }
private static Tuple <string[], string[]> GetCipherProgramValuesToUse(ProgramMenu menu, CipherInputAction menuStartingChoice) { Tuple <string[], string[]> valuesToUse; switch (menuStartingChoice) { case CipherInputAction.Predefined: { valuesToUse = menu.DisplayAndChoosePredefinedValue(); break; } case CipherInputAction.UserInput: { valuesToUse = menu.InputValues(); break; } default: { throw new Exception(SurpriseExceptionMessage); } } return(valuesToUse); }