Example #1
0
        public void HillCipherTestNewDec()
        {
            HillCipher algorithm = new HillCipher();
            string     plain     = algorithm.Decrypt(newCipher, newKey);

            Assert.IsTrue(plain.Equals(newPlain, StringComparison.InvariantCultureIgnoreCase));
        }
Example #2
0
        public void HillCipherTestDec5()
        {
            HillCipher algorithm = new HillCipher();
            string     plain     = algorithm.Decrypt(mainCipher3, mainKey3);

            Assert.IsTrue(plain.Equals(mainPlain3, StringComparison.InvariantCultureIgnoreCase));
        }
Example #3
0
        private void HillDecrypt_Click(object sender, EventArgs e)
        {
            HillCipher hillcipher = new HillCipher();

            string res = hillcipher.Decrypt(HillCipher.Text, HILLKey.Text);

            HillPlain.Text = res;
        }
        public void HillCipherTestDec2()
        {
            HillCipher algorithm = new HillCipher();

            List <int> plain2 = algorithm.Decrypt(cipher, key);

            for (int i = 0; i < plain.Count; i++)
            {
                Assert.AreEqual(plain[i], plain2[i]);
            }
        }
Example #5
0
        public void HillCipherTest1()
        {
            // 进行随机测试,测试加密密文和解密密文是否相等
            int        time   = 100;     // 测试次数
            Random     random = new Random();
            HillCipher cipher = new HillCipher(RandomHelper.GetHillMatrix());

            // 进行time次测试
            for (int i = 0; i < time; i++)
            {
                // 随机生成测试明文
                var plain = RandomHelper.GetCharList();
                var re    = cipher.Decrypt(cipher.Encrypt(plain));
                Assert.AreEqual(plain, re);
            }
        }
Example #6
0
 private void Btnd_Click(object sender, EventArgs e)
 {
     if (lastRB == radioHill) //hill
     {
         hillCipher    = hillCipher.Decrypt();
         cypheredImage = hillCipher.ImageInfo;
     }
     else if (lastRB == radioPermut) //1perutation
     {
         perm1         = perm1.Decrypt();
         cypheredImage = perm1.ImageInfo;
     }
     else if (lastRB == radioGamm)//gamma
     {
         gamma         = gamma.Decrypt();
         cypheredImage = gamma.ImageInfo;
     }
     else
     {
         SystemSounds.Exclamation.Play();
     }
     Hcypher.Text      = "H = " + cypheredImage.H;
     pictureBox2.Image = cypheredImage.Image;
 }
        public void HillCipherError3()
        {
            HillCipher algorithm = new HillCipher();

            List <int> key2 = algorithm.Decrypt(plain, keyError);
        }
Example #8
0
 private void button3_Click(object sender, EventArgs e)
 {
     if (comboBox1.Text.Contains("Ceaser"))
     {
         Ceaser c   = new Ceaser();
         string Res = c.Decrypt(textBox2.Text.ToString(), int.Parse(textBox3.Text.ToString()));
         textBox4.Text = Res;
     }
     else if (comboBox1.Text.Contains("Monoalphabetic"))
     {
         Monoalphabetic c   = new Monoalphabetic();
         string         Res = c.Decrypt(textBox2.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.Decrypt(textBox2.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 < textBox2.Text.Length; i++)
             {
                 Plaintext1.Add(int.Parse(textBox2.Text[i].ToString()));
             }
             for (int i = 0; i < textBox3.Text.Length; i++)
             {
                 key1.Add(int.Parse(textBox3.Text[i].ToString()));
             }
             ResDig        = c.Decrypt(Plaintext1, key1);
             textBox4.Text = ResDig.ToString();
         }
         else
         {
             Res           = c.Decrypt(textBox2.Text.ToString(), textBox3.Text.ToString());
             textBox4.Text = Res;
         }
     }
     else if (comboBox1.Text.Contains("PlayFair"))
     {
         PlayFair c   = new PlayFair();
         string   Res = c.Decrypt(textBox2.Text.ToString(), textBox3.Text.ToString());
         textBox4.Text = Res;
     }
     else if (comboBox1.Text.Contains("RailFence"))
     {
         RailFence c   = new RailFence();
         string    Res = c.Decrypt(textBox2.Text.ToString(), int.Parse(textBox3.Text.ToString()));
         textBox4.Text = Res;
     }
     else if (comboBox1.Text.Contains("RepeatingKeyVigenere"))
     {
         RepeatingkeyVigenere c = new RepeatingkeyVigenere();
         string Res             = c.Decrypt(textBox2.Text.ToString(), textBox3.Text.ToString());
         textBox4.Text = Res;
     }
     else if (comboBox1.Text.Contains("AutokeyVigenere"))
     {
         AutokeyVigenere c   = new AutokeyVigenere();
         string          Res = c.Decrypt(textBox2.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.Decrypt(p, q, M, ee);
         textBox4.Text = Res.ToString();
     }
     else if (comboBox1.Text.Contains("AES"))
     {
         AES    c   = new AES();
         string Res = c.Decrypt(textBox2.Text.ToString(), textBox3.Text.ToString());
         textBox4.Text = Res;
     }
 }