public void Unigraph_ColumnarTest() { Columnar columnar = new Columnar(Utility.EnglishAlphabet()); cipher = ""; clear = ""; generated = ""; for (int i = 0; i < 25; i++) { System.Collections.Generic.Dictionary <char, int> repeats = new System.Collections.Generic.Dictionary <char, int>(); foreach (char c in columnar.GenerateRandomString(7)) { if (!repeats.ContainsKey(c)) { repeats.Add(c, 0); } } StringBuilder sb = new StringBuilder(); foreach (char c in repeats.Keys) { sb.Append(c); } columnar.Key = sb.ToString(); generated = columnar.GenerateRandomString(); cipher = columnar.Encrypt(generated); clear = columnar.Decrypt(cipher); Assert.AreEqual(generated, clear);//error is missing the last character... } }
public void ColumnarNewTestDec() { Columnar algorithm = new Columnar(); string plain1 = algorithm.Decrypt(newCipher, newKey); Assert.IsTrue(plain1.Equals(newPlain, StringComparison.InvariantCultureIgnoreCase)); }
public void ColumnarTestDec2() { Columnar algorithm = new Columnar(); string plain = algorithm.Decrypt(mainCipher3, mainkey1); Assert.IsTrue(plain.Equals(mainPlain3, StringComparison.InvariantCultureIgnoreCase)); }
public void ColumnarNewTestEnc() { Columnar algorithm = new Columnar(); string cipher = algorithm.Encrypt(newPlain, newKey); Assert.IsTrue(cipher.Equals(newCipher, StringComparison.InvariantCultureIgnoreCase)); }
public void ColumnarTestEnc3() { Columnar algorithm = new Columnar(); string cipher = algorithm.Encrypt(mainPlain3, mainkey2); Assert.IsTrue(cipher.Equals(mainCipher4, StringComparison.InvariantCultureIgnoreCase) || cipher.Equals(mainCipher5, StringComparison.InvariantCultureIgnoreCase)); }
//decryption public static string Decrypt(string cipher, string key) { string plain = ""; plain = Columnar.Decrypt(cipher, key); plain = Columnar.Decrypt(plain, key); return(plain); }
public void ColumnarTestDec1() { Columnar algorithm = new Columnar(); string plain1 = algorithm.Decrypt(mainCipher1, mainkey); string plain2 = algorithm.Decrypt(mainCipher2, mainkey); Assert.IsTrue(plain1.Equals(mainPlain1, StringComparison.InvariantCultureIgnoreCase) || plain2.Equals(mainPlain2, StringComparison.InvariantCultureIgnoreCase)); }
public void ColumnarTestEnc1() { Columnar algorithm = new Columnar(); string cipher = algorithm.Encrypt(mainPlain1, mainkey); // Add x's or not Assert.IsTrue(cipher.Equals(mainCipher1, StringComparison.InvariantCultureIgnoreCase) || cipher.Equals(mainCipher2, StringComparison.InvariantCultureIgnoreCase)); }
public static string Encrypt(string plain, string key, bool pad) { string cipher = ""; string firstCipher = ""; firstCipher = Columnar.Encrypt(plain, key, pad); cipher = Columnar.Encrypt(firstCipher, key, false); return(cipher); }
public void ColumnarNewTestAnalysis() { Columnar algorithm = new Columnar(); List <int> key1 = algorithm.Analyse(newPlain, newCipher); for (int i = 0; i < newKey.Count; i++) { Assert.IsTrue(newKey[i] == key1[i]); } }
public void ColumnarTestAnalysis2() { Columnar algorithm = new Columnar(); List <int> key = algorithm.Analyse(mainPlain3, mainCipher3); for (int i = 0; i < mainkey1.Count; i++) { Assert.IsTrue(mainkey1[i] == key[i]); } }
public void ColumnarTestAnalysis1() { Columnar algorithm = new Columnar(); List <int> key1 = algorithm.Analyse(mainPlain1, mainCipher1); List <int> key2 = algorithm.Analyse(mainPlain2, mainCipher2); for (int i = 0; i < mainkey.Count; i++) { Assert.IsTrue(mainkey[i] == key1[i] || mainkey[i] == key2[i]); } }
private void button15_Click(object sender, EventArgs e) { Columnar columnar = new Columnar(); List <int> key = new List <int>(); string[] arr = ColumnarKeyBox.Text.Split(' '); for (int i = 0; i < arr.Length; i++) { key.Add(Convert.ToInt32(arr[i])); } string result = columnar.Decrypt(ColumnarCTBox.Text, key); ColumnarPTBox.Text = result; }
private void button14_Click(object sender, EventArgs e) { Columnar columnar = new Columnar(); List <int> key = columnar.Analyse(ColumnarPTBox.Text, ColumnarCTBox.Text); string result = ""; for (int i = 0; i < key.Count; i++) { if (i != key.Count - 1) { result += key[i].ToString() + " "; } else { result += key[i].ToString(); } } ColumnarKeyBox.Text = result; }
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; } }
private void button2_Click(object sender, EventArgs e) { if (comboBox1.Text.Contains("Ceaser")) { Ceaser c = new Ceaser(); int Res = c.Analyse(textBox1.Text.ToString(), textBox2.Text.ToString()); textBox4.Text = Res.ToString(); } else if (comboBox1.Text.Contains("Monoalphabetic")) { Monoalphabetic c = new Monoalphabetic(); string Res = c.Analyse(textBox1.Text.ToString(), textBox2.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())); } List <int> Res = c.Analyse(textBox1.Text.ToString(), textBox2.Text.ToString()); textBox4.Text = Res.ToString(); } 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 (textBox5.Text == "2") { if (char.IsDigit(textBox1.Text[0]) && char.IsDigit(textBox2.Text[0])) { for (int i = 0; i < textBox1.Text.Length; i++) { Plaintext1.Add(int.Parse(textBox1.Text[i].ToString())); } for (int i = 0; i < textBox2.Text.Length; i++) { key1.Add(int.Parse(textBox2.Text[i].ToString())); } ResDig = c.Analyse(Plaintext1, key1); textBox4.Text = ResDig.ToString(); } else { Res = c.Analyse(textBox1.Text.ToString(), textBox2.Text.ToString()); textBox4.Text = Res; } } else if (textBox5.Text == "3") { if (char.IsDigit(textBox1.Text[0]) && char.IsDigit(textBox2.Text[0])) { for (int i = 0; i < textBox1.Text.Length; i++) { Plaintext1.Add(int.Parse(textBox1.Text[i].ToString())); } for (int i = 0; i < textBox2.Text.Length; i++) { key1.Add(int.Parse(textBox2.Text[i].ToString())); } ResDig = c.Analyse3By3Key(Plaintext1, key1); textBox4.Text = ResDig.ToString(); } else { Res = c.Analyse3By3Key(textBox1.Text.ToString(), textBox2.Text.ToString()); textBox4.Text = Res; } } } else if (comboBox1.Text.Contains("RailFence")) { RailFence c = new RailFence(); int Res = c.Analyse(textBox1.Text.ToString(), textBox2.Text.ToString()); textBox4.Text = Res.ToString(); } else if (comboBox1.Text.Contains("RepeatingKeyVigenere")) { RepeatingkeyVigenere c = new RepeatingkeyVigenere(); string Res = c.Analyse(textBox1.Text.ToString(), textBox2.Text.ToString()); textBox4.Text = Res; } else if (comboBox1.Text.Contains("AutokeyVigenere")) { AutokeyVigenere c = new AutokeyVigenere(); string Res = c.Analyse(textBox1.Text.ToString(), textBox2.Text.ToString()); textBox4.Text = Res; } }