public ActionResult DocxEncode(UploadedFile file) { lastKeyFile = file.KeyFile; lastFileName = file.FileName; try { //"application/vnd.openxmlformats-officedocument.wordprocessingml.document" using (MemoryStream ms = new MemoryStream()) { byte[] arr = new byte[file.UploadedFileValue.ContentLength]; file.UploadedFileValue.InputStream.Read(arr, 0, file.UploadedFileValue.ContentLength); ms.Write(arr, 0, arr.Length); string body = Parser.ParseDocx(ms); body = Vigenere.Encode(body, file.KeyFile); byte[] result = Parser.SaveDocx(body); string fName = "Encoded.docx"; if (file.FileName != null) { fName = file.FileName + ".docx"; } return(File(result, "application/docx", fName)); } } catch (Exception e) { lastKeyFile = e.Message; return(Redirect("/Home")); } }
public void IndexEncodeTextTest() { RedirectResult redir = controller.TextEncode(new Text("Привет мир!", "б", "test")) as RedirectResult; result = controller.Index() as ViewResult; Assert.AreEqual(Vigenere.Encode("Привет мир!", "б"), result.ViewBag.TextValue); }
public void Encode_OnlyNumbers() // Проверка зашифровки файла содержащего только цифры { string input = File.ReadAllText(@"../../testFiles/Encoding/Test4.txt", Encoding.Default); string expectedResult = File.ReadAllText(@"../../testFiles/Decoding/Test4.txt", Encoding.UTF8); input = Vigenere.Encode(input, "скорпион"); Assert.AreEqual(input, expectedResult); }
public void Encode_OnlyLatinAlphabet() // Проверка зашифровки файла содержащего только латинский алфавит { string input = File.ReadAllText(@"../../testFiles/Encoding/Test3.txt", Encoding.Default); string expectedResult = File.ReadAllText(@"../../testFiles/Decoding/Test3.txt", Encoding.UTF8); input = Vigenere.Encode(input, "скорпион"); Assert.AreEqual(input, expectedResult); }
public void Encode_CyrilicLettersAndNumbers() // Проверка зашифровки файла содержащего цифры, буквы и пробельные символы { string input = File.ReadAllText(@"../../testFiles/Encoding/Test2.txt", Encoding.Default); string expectedResult = File.ReadAllText(@"../../testFiles/Decoding/Test2.txt", Encoding.UTF8); input = Vigenere.Encode(input, "скорпион"); Assert.AreEqual(input, expectedResult); }
public void EncodeEmpty() { string text = ""; string key = "б"; string result = Vigenere.Encode(text, key); Assert.AreEqual("", result); }
public void EncodeWrongLetters() { string text = "Пrи8еТ"; string key = "б"; string result = Vigenere.Encode(text, key); Assert.AreEqual("Рrй8ёУ", result); }
public void EncodeUpperLetters() { string text = "ПривеТ"; string key = "б"; string result = Vigenere.Encode(text, key); Assert.AreEqual("РсйгёУ", result); }
public void KeyCheckUpper() { string text = "аааааа"; string key = "Абв"; string result = Vigenere.Encode(text, key); Assert.AreEqual("абвабв", result); }
public void EncodeLowerLetters() { string text = "привет"; string key = "б"; string result = Vigenere.Encode(text, key); Assert.AreEqual("рсйгёу", result); }
static void HomeworkSection2() { // Generate random key with the same length as the keyword. randomKeyword = Utilities.GenerateRandomKey(keywordText.Length); Console.WriteLine($"Selected Random Key: {randomKeyword}"); // Encrypt cipher text with the random key. Vigenere vigenere = new Vigenere(); cipherText = vigenere.Encode(cipherText, randomKeyword); // Apply same crypto analysis methods in section 1. HomeworkSection1(); }
public void EncodeNull() { string text = null; string key = "б"; try { string result = Vigenere.Encode(text, key); } catch (Exception e) { Assert.AreEqual("Текст не может быть пустым!", e.Message); } }
public void KeyCheckNull() { string text = "ааааааа"; string key = null; try { Vigenere.Encode(text, key); } catch (Exception e) { Assert.AreEqual("Отсутствует ключ!", e.Message); } }
public void KeyCheckWrongFormat() { string text = "ааааааа"; string key = "Abc"; try { Vigenere.Encode(text, key); } catch (Exception e) { Assert.AreEqual("Ключ введен в неверном формате!", e.Message); } }
public ActionResult TextEncode(Text text) { try { lastTextValue = Vigenere.Encode(text.TextValue, text.KeyText); lastKeyText = text.KeyText; } catch (Exception e) { lastKeyText = e.Message; lastTextValue = text.TextValue; } lastTextName = text.TextName; return(Redirect("/Home")); }