private void CipherChoise(int num) { switch (num) { case 1: Morse_Cipher.StartMorse(); break; case 3: CesarCipher.StartCaesar(); break; case 2: Console.WriteLine("It is the Transposition code!"); Console.WriteLine("Enter the number for action!"); Console.WriteLine("1. To Transposition"); Console.WriteLine("2. From Transposition"); break; case 4: Console.WriteLine("Hello!"); Console.WriteLine("Enter the number of cipher!"); Console.WriteLine("1. Morse"); Console.WriteLine("2. Transposition"); Console.WriteLine("3. Caesar's"); Console.WriteLine("4. Combo"); break; default: break; } }
public static void StartCaesar() { bool exitStr = true; while (exitStr) { try { ClassMessDisplay.CaesarScreen(); string choise = Console.ReadLine(); if (GeneralCipherClass.SelectEnterForExit(choise)) { break; } int number = int.Parse(choise); CesarCipher cesarCode; if (number <= 3 & number >= 1) { switch (number) { case 1: Console.Clear(); Console.WriteLine("Enter a shift number"); int shift = Int32.Parse(Console.ReadLine()); Console.Clear(); Console.WriteLine("Enter Word"); string val1 = Console.ReadLine(); cesarCode = new CesarCipher(shift); cesarCode.crypt(val1); ClassMessDisplay.OutQuestionOfContinueScreen(); val1 = Console.ReadLine(); exitStr = SelectContinueAct(val1); break; case 2: Console.Clear(); Console.WriteLine("Enter Word"); string val2 = Console.ReadLine(); cesarCode = new CesarCipher(Int32.Parse(val2)); cesarCode.decrypt(val2); break; default: break; } } else { throw new Exception(); } } catch (Exception) { Console.WriteLine("Wrong digit entered"); } } }
public void Base() { var sut = new CesarCipher(); const string input = "secret"; const byte padding = 5; var encoded = sut.Encode(input, padding); Assert.Equal(input, sut.Decode(encoded, padding)); }
public void LongString() { var sut = new CesarCipher(); const string input = "klYyn23RSBfVn8bqbQa2TRpTWjAkiHM5rL2YTDCl6DOQLdT2nj3kBb8GKLxdyj5Hx56SURDBGPFFEOKdwWA14YIJTwtHV7yqYqSbYOvYkbKKCXP3jsCMGH4xNyeGqQBoIKrR3hLh9YIqVLDp1Nq942xj10Qe8Nk67oCfMWYciqLnS6bwIiaRg5XIImegDHbqq6Iod79bZEAB7ziY2hoimMNB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IbBmekVAeBYq0F8bQN1jZlf1mUnbvhpc08k3goM8cIxzsMm9mvhtSjFqOltzi15CWxOMT4wwz3hOITtaV0IHRiZhymuOal2NNevhHfwYjWeac9bq8oNhvppLpjlvkGz18nHTqoxTfREaex7AcIJEofNGLuGb9jmODf6MbiscaeklZ1qMfg5gmLdPYiqz4KCQ55V5UJwWwljNCLPw3grVKRAsZtSohmaEK4VyaFaoNdGsfm2BsQ7oZvRQ62TvjVmbrmqBEV6paDktwuYyEfhFRW0beuwDapXvLnnzzYeZU4ZT5Yew2QiSItfq6y4ioYd48x1rcrBx1pYZ6za6D5LGkNgL9KQk6Bf3hY9TDBNM7YnjJGwUr1KGWh8SnCGcoLGqFMI2GvW7Yd2l86mGjBpF0j7aw7iJ2JEFaVZF3R0SmWUACtRgUCtMwFO13gkpz6Ct62MtbLpOTC4OboAdEYDuxNXMymHhYCAqsHgRgNy9Qc23Uzc0ntEZAiQg0Rbf3bCLR7u7IObl4k18HKHKnHEX3Aiyyv51opQXax18UUbw2Mbhz4NalIpgNkmvxlUuKdaUyEWCYKcbGCcRdKEG6eubcbnlSqRtwPI411qLzawuUSz5K9S2Y0l96IMdzkjjn5orisIlRlFVdIXM5ucw5LV6Z0MRT1BPxK2c6WVmpufakwXaISQrukBf71WY8cR49NRh8M"; const byte padding = (byte)5; var encoded = sut.Encode(input, padding); Assert.Equal(input, sut.Decode(encoded, padding)); }
public ActionResult Upload(HttpPostedFileBase uploadFile, string uploadtext, string range, string acionButton) { //checking of incoming values if (uploadFile == null && uploadtext.Length < 1) { return(RedirectToAction("Index", "Home")); } // Verify that the user put something in textarea if (uploadtext != "") { filetext = uploadtext; } //reading file if (uploadFile != null && uploadFile.ContentLength > 0) { fileName = uploadFile.FileName; if (uploadFile.FileName.EndsWith(".txt")) { filetext = ReadingFromText.TxtReader(uploadFile.InputStream); } else { filetext = ReadingFromText.DocxReader(uploadFile.InputStream); } } //action switching switch (acionButton) { case "encrypt": //encrypping filetext = CesarCipher.Cipher(filetext, int.Parse(range)); ViewData["text"] = filetext; return(View("Upload")); case "decrypt with key": //decrypping whith key filetext = CesarCipher.Cipher(filetext, -int.Parse(range)); ViewData["text"] = filetext; return(View("Upload")); case "decrypt without key": //decrypping without key var indexes = CesarCipher.FindKey(filetext); string[] texts = new string[indexes.Length]; for (int i = 0; i < indexes.Length; i++) { texts[i] = CesarCipher.Cipher(filetext, -indexes[i]); } ViewBag.index = indexes; ViewBag.text = texts; return(View("Result")); default: return(View()); } }
public void Fuzzy() { var sut = new CesarCipher(); const int inputLength = 10000; var stringBuilder = new StringBuilder(inputLength); var random = new Random(); const byte minSymbol = (byte)'0'; const byte maxSymbol = (byte)'~'; for (var i = 0; i < inputLength; i++) { stringBuilder.Append((char)random.Next(minSymbol, maxSymbol)); } var input = stringBuilder.ToString(); const byte padding = 5; var encoded = sut.Encode(input, padding); Assert.Equal(input, sut.Decode(encoded, padding)); }