public ActionResult DocxDecode(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.Decode(body, file.KeyFile); byte[] result = Parser.SaveDocx(body); string fName = "Decoded.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 IndexDecodeTextTest() { RedirectResult redir = controller.TextDecode(new Text("Привет мир!", "б", "test")) as RedirectResult; result = controller.Index() as ViewResult; Assert.AreEqual(Vigenere.Decode("Привет мир!", "б"), result.ViewBag.TextValue); }
static bool HomeworkSection1() { // Start finding key with only known cipher text attack bool successfull = DecryptWithKnownCipherText(); // If known cipher text attack has not been successfull, try known plain text and cipher text attack. if (!successfull) { successfull = DecryptWithKnownPlainAndCipherText(); } if (successfull) { // Decode the cipher text with the found keyword to check whether the found keyword is correct or not. Vigenere vigenere = new Vigenere(); string decodedText = vigenere.Decode(cipherText, keywordText); if (decodedText == plainText) { Console.WriteLine("Cipher text decrypted successfully!"); } } return(successfull); }
public void Decode_OnlyNumbers() // Проверка зашифровки файла содержащего только цифры { string input = File.ReadAllText(@"../../testFiles/Decoding/Test4.txt", Encoding.UTF8); string expectedResult = File.ReadAllText(@"../../testFiles/Encoding/Test4.txt", Encoding.Default); input = Vigenere.Decode(input, "скорпион"); Assert.AreEqual(input, expectedResult); }
public void Decode_OnlyLatinAlphabet() // Проверка зашифровки файла содержащего только латинский алфавит { string input = File.ReadAllText(@"../../testFiles/Decoding/Test3.txt", Encoding.UTF8); string expectedResult = File.ReadAllText(@"../../testFiles/Encoding/Test3.txt", Encoding.Default); input = Vigenere.Decode(input, "скорпион"); Assert.AreEqual(input, expectedResult); }
public void Decode_CyrilicLettersAndNumbers() // Проверка зашифровки файла содержащего цифры, буквы и пробельные символы { string input = File.ReadAllText(@"../../testFiles/Decoding/Test2.txt", Encoding.UTF8); string expectedResult = File.ReadAllText(@"../../testFiles/Encoding/Test2.txt", Encoding.Default); input = Vigenere.Decode(input, "скорпион"); Assert.AreEqual(input, expectedResult); }
public void Decode_OnlyCyrillicLetters() // Проверка шифрования файла содержащего только буквы и пробельные символы { string input = File.ReadAllText(@"../../testFiles/Decoding/Test1.txt", Encoding.UTF8); string expectedResult = File.ReadAllText(@"../../testFiles/Encoding/Test1.txt", Encoding.Default); input = Vigenere.Decode(input, "скорпион"); Assert.AreEqual(input, expectedResult); }
public void DecodeEmpty() { string text = ""; string key = "б"; string result = Vigenere.Decode(text, key); Assert.AreEqual("", result); }
public void DecodeWrongLetters() { string text = "Пrи8еТ"; string key = "б"; string result = Vigenere.Decode(text, key); Assert.AreEqual("Оrз8дС", result); }
public void DecodeUpperLetters() { string text = "ПривеТ"; string key = "б"; string result = Vigenere.Decode(text, key); Assert.AreEqual("ОпзбдС", result); }
public void DecodeLowerLetters() { string text = "привет"; string key = "б"; string result = Vigenere.Decode(text, key); Assert.AreEqual("опзбдс", result); }
public void DecodeNull() { string text = null; string key = "б"; try { string result = Vigenere.Decode(text, key); } catch (Exception e) { Assert.AreEqual("Текст не может быть пустым!", e.Message); } }
public ActionResult TextDecode(Text text) { try { lastTextValue = Vigenere.Decode(text.TextValue, text.KeyText); lastKeyText = text.KeyText; } catch (Exception e) { lastKeyText = e.Message; lastTextValue = text.TextValue; } lastTextName = text.TextName; return(Redirect("/Home")); }