示例#1
0
        public void SubsitutionCipher()
        {
            string text = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            string cipher = "DSJLPMECOGNWZ";

            SubstitutionCipher sc = new SubstitutionCipher(text, cipher);
            string textEncrypt = sc.Encrypt(text);
            System.Console.Out.WriteLine(text);
            System.Console.Out.WriteLine(textEncrypt);
            Assert.That(text != textEncrypt);

            string textDecrypt = sc.Decrypt(textEncrypt);

            System.Console.Out.WriteLine(text);
            System.Console.Out.WriteLine(textDecrypt);
            Assert.That(text == textDecrypt);
        }
示例#2
0
        public void RandomSubstitutionCipherNonCaseSensitive()
        {
            for (int i = 0; i < 500; i++)
            {
                string text = ToolCipher.GenerateText(ToolCipher.AllChar, 500);
                string plain = ToolCipher.abc + ToolCipher.Number0At9;
                string cipher = ToolCipher.MixedString(plain, 10);

                SubstitutionCipher sc = new SubstitutionCipher(plain, cipher);

                string textEncrypt = sc.Encrypt(text);
                System.Console.Out.WriteLine(text);
                System.Console.Out.WriteLine(textEncrypt);
                Assert.That(text != textEncrypt);

                string textDecrypt = sc.Decrypt(textEncrypt);

                System.Console.Out.WriteLine(text);
                System.Console.Out.WriteLine(textDecrypt);
                Assert.That(text == textDecrypt);
            }
        }
示例#3
0
 public bool ValidParameter()
 {
     try
     {
         if (sc == null)
         {
             sc = new SubstitutionCipher(textBoxTargeted.Text, textBoxSubstituted.Text, checkBoxCaseSensitive.Checked);
         }
         else
         {
             sc.Plain = textBoxTargeted.Text;
             sc.Cipher = textBoxSubstituted.Text;
             sc.CaseSensitive = checkBoxCaseSensitive.Checked;
         }
     }
     catch(Exception e)
     {
         MessageBox.Show(e.Message, "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return false;
     }
     return true;
 }
示例#4
0
 private void SubsitutionCipherChange()
 {
     _sc = new SubstitutionCipher(_plain, _plain.Substring(_shift) + _plain.Substring(0, _shift), false);
 }