public void RailFenceTestNewEnc() { RailFence algorithm = new RailFence(); string cipher = algorithm.Encrypt(newPlain, newkey); Assert.IsTrue(cipher.Equals(newCipher, StringComparison.InvariantCultureIgnoreCase)); }
public void RailFenceTestEnc1() { RailFence algorithm = new RailFence(); string cipher = algorithm.Encrypt(mainPlain1, mainKey); Assert.IsTrue(cipher.Equals(mainCipher, StringComparison.InvariantCultureIgnoreCase)); }
public void EncryptBasic() { RailFence rf3 = new RailFence(3); var output = rf3.Encrypt(BasicText); Assert.AreEqual("DNETLEEDHESWLFTAA", output); }
public void EncryptBasic2() { RailFence rf4 = new RailFence(4); var output = rf4.Encrypt(BasicText); Assert.AreEqual("DTTEDHSWFNEAALEEL", output); }
public void Unigraph_RailFenceTest() { RailFence railfence = new RailFence(Utility.KeyedEnglishAlphabet("KRYPTOS")); cipher = ""; clear = ""; generated = ""; byte[] tokenData = new byte[2]; using (System.Security.Cryptography.RandomNumberGenerator rng = new System.Security.Cryptography.RNGCryptoServiceProvider()) { rng.GetBytes(tokenData); railfence.Key = (int)(BitConverter.ToUInt16(tokenData, 0) >> 8); for (int i = 0; i < 25; i++) { generated = railfence.GenerateRandomString(); cipher = railfence.Encrypt(generated); clear = railfence.Decrypt(cipher); Assert.AreEqual(generated, clear); } } }
public void RailFenceTestEnc2() { RailFence algorithm = new RailFence(); string cipher = algorithm.Encrypt(mainPlain1, mainKey2); // Add x's or not Assert.IsTrue(cipher.Equals(mainCipher2, StringComparison.InvariantCultureIgnoreCase) || cipher.Equals(mainCipher3, StringComparison.InvariantCultureIgnoreCase)); }
/// <summary> /// Performs one of the possible actions: encrypts or decrypts data. /// </summary> /// <param name="text">Data to be encrypted / decrypted.</param> /// <param name="key">The key for the encryption / decryption algorithm.</param> /// <param name="typeOfChiper">The name of the encryption / decryption algorithm.</param> /// <param name="action">Action to be taken (encrypt / decrypt).</param> /// <returns>The result of encryption / decryption.</returns> private static string PerformAction(string text, string key, TypesOfCiphers typeOfChiper, Model.Ciphers.Action action) { switch (typeOfChiper) { case TypesOfCiphers.RailFence: RailFence railFence = new RailFence(); if (action == Model.Ciphers.Action.Encrypt) { return(railFence.Encrypt(text, key)); } else { return(railFence.Decrypt(text, key)); } case TypesOfCiphers.RotatingSquare: RotatingGrill rotatingSquare = new RotatingGrill(); if (action == Model.Ciphers.Action.Encrypt) { return(rotatingSquare.Encrypt(text)); } else { return(rotatingSquare.Decrypt(text)); } case TypesOfCiphers.Vigenere: Vigenere vigener = new Vigenere(); if (action == Model.Ciphers.Action.Encrypt) { try { return(vigener.Encrypt(text, key)); } catch (DivideByZeroException) { return(text); } } else { try { return(vigener.Decrypt(text, key)); } catch (DivideByZeroException) { return(text); } } default: return(null); } }
public void ReturnsUnchangedWordFor1KeyEncryption() { string input = "Dsadajkaajddjh"; RailFence railFence = new RailFence(1); string encrypted = railFence.Encrypt(input); Assert.AreEqual(input, encrypted); }
public void ReturnsInitialWordAfterBothDecryptionAndEncryption() { string input = "CRYPTOGRAPHY"; RailFence railFence = new RailFence(3); string res = railFence.Decrypt(input); string encrypted = railFence.Encrypt(res); Assert.AreEqual(encrypted, input); }
public void ReturnsEncryptedWordForKeyShorterThanWord() { string input = "CRYPTOGRAPHY"; string expected = "CTARPORPYYGH"; RailFence railFence = new RailFence(3); string encrypted = railFence.Encrypt(input); Assert.AreEqual(encrypted, expected); }
private void RailEncrypt_Click(object sender, EventArgs e) { RailFence railfence = new RailFence(); string res = ""; if (RailKey.Text != null) { res = railfence.Encrypt(PlainText.Text, int.Parse(RailKey.Text)); } else { MessageBox.Show("enter key value"); } CipherText.Text = res; }
private void RailFenceEncode(object sender, RoutedEventArgs e) { RailFence algorithm = new RailFence(); string value = RailFenceEncodeInput.Text; int key; try { key = Int32.Parse(RailFenceEncodeKeyInput.Text); } catch (Exception ex) { MessageBox.Show("Podano złą wagę", "Zła waga", MessageBoxButton.OK, MessageBoxImage.Error); return; } RailFenceEncodeOutput.Text = algorithm.Encrypt(value, key); }
private void encryptDecryptPressed(object sender, RoutedEventArgs e) { string buttonName = ((Button)sender).Name; string userInput = mTextBox.Text.ToString(); string userKey = keyTextBox.Text.ToString(); string encrypted = ""; string decrypted = ""; bool normalDialog = true; switch (currentAlgorithm) { case "RAIL_FENCE": if (mTextBox.Text == "") { MessageBox.Show("Rail fence text input is empty. Please type in something."); return; } if (validateRailfenceFields(keyTextBox.Text.ToString())) { int i = int.Parse(userKey); rf = new RailFence(i); encrypted = rf.Encrypt(userInput); decrypted = rf.Decrypt(userInput); } break; case "COLUMNAR_TRANSP": if (mTextBox.Text == "") { MessageBox.Show("Columanr transp text input is empty. Please type in something."); return; } int[] inputTab = parseColumnarTranspKey(userKey); if (validateColumnarTranspkey(inputTab)) { ct = new ColumnarTransposition(parseColumnarTranspKey(userKey)); encrypted = ct.Encrypt(userInput); decrypted = ct.Decrypt(userInput); } else { return; } break; case "MATRIX_TRANSP": if (mTextBox.Text == "") { MessageBox.Show("Matrix transp text input is empty. Please type in something."); return; } if (validateMatrixTransp(userKey)) { mt = new MatrixTransp(parseMatrixTranspKey(userKey)); encrypted = mt.Encrypt(userInput); decrypted = mt.Decrypt(userInput); } else { return; } break; case "COLUMNAR_C": if (mTextBox.Text == "") { MessageBox.Show("Matrix transp version C text input is empty. Please type in something."); return; } if (validateMatrixTranspVerCKey(userKey) && validateMatrixTranspVerCWord(userInput)) { ctc = new ColumnarTranspositionC(userKey); encrypted = ctc.Encrypt(userInput); decrypted = ctc.Decrypt(userInput); } else { return; } break; case "ViGENERE": if (mTextBox.Text == "") { MessageBox.Show("Winegret text input is empty. Please type in something."); return; } if (validateVinegretKey(userKey) && validateVinegretWord(userInput)) { vig = new Vigenere(userKey); encrypted = vig.Encrypt(userInput); decrypted = vig.Decrypt(userInput); } else { return; } break; case "CEZAR": if (mTextBox.Text == "") { MessageBox.Show("Cezar text input is empty. Please type in something."); return; } if (validateCezarKey(userKey) && validateCezarWord(userInput)) { int i = int.Parse(userKey); cz = new Cezar(i); encrypted = cz.Encrypt(userInput); decrypted = cz.Decrypt(userInput); } else { return; } break; case "SYNC": if (syncFileName.Content.ToString() == " ") { MessageBox.Show("SYNC file input is empty. Please type in something."); return; } if (keyTextBox.Text == "") { MessageBox.Show("SYNC key text input is empty. Please type in something."); return; } if (!syncKeyGenerated) { MessageBox.Show("SYNC key needs to be generated first, please press run and then stop button before proceeding."); return; } normalDialog = false; synchronousStreamCipher = new SynchronousStreamCipher(lsfrGen.GetSequence()); TextWriter tw = new StreamWriter("LFSR KEY USED.txt"); List <bool> listOfBools = lsfrGen.GetSequence(); char boolOutcome = ' '; string boolOutcomeCollection = ""; int ij = 0; foreach (bool b in listOfBools) { if (b == true) { boolOutcome = '1'; } else { boolOutcome = '0'; } boolOutcomeCollection += boolOutcome; ij++; if (ij > 100) { ij = 0; tw.WriteLine(boolOutcomeCollection); boolOutcomeCollection = ""; } } tw.WriteLine(boolOutcomeCollection); tw.Close(); if (buttonName == "encrypt") { synchronousStreamCipher.Encrypt(syncFileName.Content.ToString()); } else { synchronousStreamCipher.Decrypt(syncFileName.Content.ToString()); } MessageBox.Show("Encrypted/decrypted file is located in folder where your .exe file is ( most probably bin/debug ). You will also find text file that contains LFSR key in it there."); break; case "DES": if (syncFileName.Content.ToString() == " ") { MessageBox.Show("DES file input is empty. Please type in something."); return; } if (keyTextBox.Text == "") { MessageBox.Show("DES key text input is empty. Please type in something."); return; } if (!validateDesKey(userKey)) { return; } des = new DES(desKeyParsing(userKey)); if (buttonName == "encrypt") { des.EncryptFile(syncFileName.Content.ToString()); } else { des.DecryptFile(syncFileName.Content.ToString()); } MessageBox.Show("Encrypted/decrypted file is located in folder where your .exe file is ( most probably bin/debug )."); break; default: break; } int length = encrypted.Length; outcomeLabel.FontSize = 30; if (length > 10) { outcomeLabel.FontSize = 20; } if (length > 20) { outcomeLabel.FontSize = 15; } if (normalDialog) { if (buttonName == "encrypt") { if (encrypted != "") { outcomeTypeLabel.Content = "Encrypted:"; } outcomeLabel.Content = encrypted; } else { if (decrypted != "") { outcomeTypeLabel.Content = "Decrypted:"; } outcomeLabel.Content = decrypted; } } else { } }
public void RailFenceEncode(string input, int key, string output) { var result = railFence.Encrypt(input, key); Assert.AreEqual(output, result); }
private void RailFenceEncrypt_Click(object sender, EventArgs e) { RailFenceOutput.Text = RailFence.Encrypt(RailFenceInput.Text, Convert.ToInt32(Rails.Value)); }
private void button1_Click(object sender, EventArgs e) { if (comboBox1.Text.Contains("Ceaser")) { Ceaser c = new Ceaser(); string Res = c.Encrypt(textBox1.Text.ToString(), int.Parse(textBox3.Text.ToString())); textBox4.Text = Res; } else if (comboBox1.Text.Contains("Monoalphabetic")) { Monoalphabetic c = new Monoalphabetic(); string Res = c.Encrypt(textBox1.Text.ToString(), textBox3.Text.ToString()); textBox4.Text = Res; } else if (comboBox1.Text.Contains("Columnar")) { Columnar c = new Columnar(); List <int> key = new List <int>(); for (int i = 0; i < textBox3.Text.Length; i++) { key.Add(int.Parse(textBox3.Text[i].ToString())); } string Res = c.Encrypt(textBox1.Text.ToString(), key); textBox4.Text = Res; } else if (comboBox1.Text.Contains("HillCipher")) { HillCipher c = new HillCipher(); List <int> key1 = new List <int>(); List <int> Plaintext1 = new List <int>(); string Res = ""; List <int> ResDig = new List <int>(); if (char.IsDigit(textBox3.Text[0]) && char.IsDigit(textBox1.Text[0])) { for (int i = 0; i < textBox1.Text.Length; i++) { Plaintext1.Add(int.Parse(textBox1.Text[i].ToString())); } for (int i = 0; i < textBox3.Text.Length; i++) { key1.Add(int.Parse(textBox3.Text[i].ToString())); } ResDig = c.Encrypt(Plaintext1, key1); textBox4.Text = ResDig.ToString(); } else { Res = c.Encrypt(textBox1.Text.ToString(), textBox3.Text.ToString()); textBox4.Text = Res; } } else if (comboBox1.Text.Contains("PlayFair")) { PlayFair c = new PlayFair(); string Res = c.Encrypt(textBox1.Text.ToString(), textBox3.Text.ToString()); textBox4.Text = Res; } else if (comboBox1.Text.Contains("RailFence")) { RailFence c = new RailFence(); string Res = c.Encrypt(textBox1.Text.ToString(), int.Parse(textBox3.Text.ToString())); textBox4.Text = Res; } else if (comboBox1.Text.Contains("RepeatingKeyVigenere")) { RepeatingkeyVigenere c = new RepeatingkeyVigenere(); string Res = c.Encrypt(textBox1.Text.ToString(), textBox3.Text.ToString()); textBox4.Text = Res; } else if (comboBox1.Text.Contains("AutokeyVigenere")) { AutokeyVigenere c = new AutokeyVigenere(); string Res = c.Encrypt(textBox1.Text.ToString(), textBox3.Text.ToString()); textBox4.Text = Res; } else if (comboBox1.Text.Contains("RSA")) { RSA c = new RSA(); string s = textBox1.Text.ToString(); string[] str = s.Split(' '); int p = int.Parse(str[0]); int q = int.Parse(str[1]); int M = int.Parse(str[2]); int ee = int.Parse(str[3]); int Res = c.Encrypt(p, q, M, ee); textBox4.Text = Res.ToString(); } else if (comboBox1.Text.Contains("AES")) { AES c = new AES(); string Res = c.Encrypt(textBox1.Text.ToString(), textBox3.Text.ToString()); textBox4.Text = Res; } else if (comboBox1.Text.Contains("MD5")) { MD5 c = new MD5(); string Res = c.GetHash(textBox1.Text.ToString()); textBox4.Text = Res; } }