示例#1
0
        public void TwofishTestMethod()
        {
            var pluginInstance = TestHelpers.GetPluginInstance("Twofish");
            var scenario       = new PluginTestScenario(pluginInstance, new[] { "InputStream", "KeyData", ".Action", ".Mode", ".KeySize", ".Mode", ".Padding" }, new[] { "OutputStream" });

            object[] output;

            foreach (TestVector vector in testvectors)
            {
                output = scenario.GetOutputs(new object[] { vector.input.HexToStream(), vector.key.HexToByteArray(), 0, 0, vector.keysize, 0, 0 });
                Assert.AreEqual(vector.output.ToUpper(), output[0].ToHex(), "Unexpected value in test #" + vector.n + ".");
            }

            foreach (TestVector vector in testvectors_loop)
            {
                string input, key, cipher;
                input = cipher = key = "00000000000000000000000000000000";

                for (int i = 0; i < 49; i++)
                {
                    key    = (input + key).Substring(0, (128 + vector.keysize * 64) / 4);
                    input  = cipher;
                    output = scenario.GetOutputs(new object[] { input.HexToStream(), key.HexToByteArray(), 0, 0, vector.keysize, 0, 0 });
                    cipher = output[0].ToHex();
                }
                Assert.AreEqual(vector.output.ToUpper(), cipher, "Unexpected value in test loop #" + vector.n + ".");
            }
        }
示例#2
0
        public void M209TestMethod()
        {
            var pluginInstance = TestHelpers.GetPluginInstance("M209");
            var scenario       = new PluginTestScenario(pluginInstance, new[] { "Text", ".Startwert",
                                                                                ".Rotor1", ".Rotor2", ".Rotor3", ".Rotor4", ".Rotor5", ".Rotor6",
                                                                                ".Bar1", ".Bar2", ".Bar3", ".Bar4", ".Bar5", ".Bar6", ".Bar7", ".Bar8", ".Bar9", ".Bar10",
                                                                                ".Bar11", ".Bar12", ".Bar13", ".Bar14", ".Bar15", ".Bar16", ".Bar17", ".Bar18", ".Bar19", ".Bar20",
                                                                                ".Bar21", ".Bar22", ".Bar23", ".Bar24", ".Bar25", ".Bar26", ".Bar27" }, new[] { "OutputString" });

            object[] output;

            foreach (TestVector vector in testvectors)
            {
                List <object> parameters = new List <object> {
                    vector.input, vector.key
                };
                foreach (var pin in vector.pins)
                {
                    parameters.Add(pin);
                }
                foreach (var slider in vector.sliders)
                {
                    parameters.Add(slider);
                }

                output = scenario.GetOutputs(parameters.ToArray());
                Assert.AreEqual(vector.output, (string)output[0], "Unexpected value in test #" + vector.n + ".");
            }
        }
示例#3
0
        public void CRCTestMethod()
        {
            var pluginInstance = TestHelpers.GetPluginInstance("CRC");
            var scenario1      = new PluginTestScenario(pluginInstance, new[] { "InputStream", ".Width", ".Polynomial", ".Init", ".XorOut", ".RefIn", ".RefOut" }, new[] { "OutputStream" });
            var scenario2      = new PluginTestScenario(pluginInstance, new[] { "InputStream", ".CRCMethod" }, new[] { "OutputStream" });

            object[] output;

            var   input = "313233343536373839".HexToStream(); // "123456789" as Stream
            ulong check;

            for (int method = 0; method < testvectors.Length; method++)
            {
                TestVector vector = testvectors[method];

                // set CRC parameters individually
                output = scenario1.GetOutputs(new object[] { input, vector.width, vector.polynomial.ToString("x"), vector.init.ToString("x"), vector.xorout.ToString("x"), vector.refin, vector.refout });
                check  = stream2ulong(output[0] as ICryptoolStream);
                Assert.AreEqual(vector.check.ToString("x"), check.ToString("x"), "Unexpected value in test '" + vector.name + "'.");

                // set CRC parameters by selecting a CRCMethod
                output = scenario2.GetOutputs(new object[] { input, method });
                check  = stream2ulong(output[0] as ICryptoolStream);
                Assert.AreEqual(vector.check.ToString("x"), check.ToString("x"), "Unexpected value in test '" + vector.name + "'.");
            }
        }
示例#4
0
        public void SHATestMethod()
        {
            var pluginInstance = TestHelpers.GetPluginInstance("SHA");
            var scenario1      = new PluginTestScenario(pluginInstance, new[] { "InputData", ".SHAFunction" }, new[] { "OutputDataStream" });
            var scenario2      = new PluginTestScenario(pluginInstance, new[] { "InputData", ".SHAFunction" }, new[] { "OutputData" });

            object[] output;

            foreach (TestVector vector in testvectors)
            {
                output = scenario1.GetOutputs(new object[] { vector.input.ToStream(), vector.mode });
                Assert.AreEqual(vector.output.ToUpper(), output[0].ToHex(), "Unexpected value in test #" + vector.n + ".");
                output = scenario2.GetOutputs(new object[] { vector.input.ToStream(), vector.mode });
                Assert.AreEqual(vector.output.ToUpper(), output[0].ToHex(), "Unexpected value in test #" + vector.n + ".");
            }

            foreach (TestVector vector in testvectors_loop)
            {
                ICryptoolStream input = vector.input.ToStream();
                for (int i = 0; i < 100000; i++)
                {
                    input = (ICryptoolStream)scenario1.GetOutputs(new object[] { input, vector.mode })[0];
                }
                Assert.AreEqual(vector.output.ToUpper(), input.ToHex(), "Unexpected value in iteration test #" + vector.n + ".");
            }
        }
示例#5
0
        public void HMACTestMethod()
        {
            var pluginInstance = TestHelpers.GetPluginInstance("HMAC");
            var scenarios      = new PluginTestScenario[] {
                new PluginTestScenario(pluginInstance, new[] { "InputData", "Key", ".SelectedHashFunction" }, new[] { "OutputData" }),
                new PluginTestScenario(pluginInstance, new[] { "InputData", "Key", ".SelectedHashFunction" }, new[] { "OutputDataStream" })
            };

            object[] output;

            foreach (var scenario in scenarios)
            {
                foreach (TestVector vector in testvectors1)
                {
                    output = scenario.GetOutputs(new object[] { vector.input.ToStream(), vector.key.ToByteArray(), vector.mode });
                    Assert.AreEqual(vector.output.ToUpper(), output[0].ToHex(), "Unexpected value in test #" + vector.n + ".");
                }

                foreach (TestVector vector in testvectors2)
                {
                    output = scenario.GetOutputs(new object[] { vector.input.ToStream(), vector.key.HexToByteArray(), vector.mode });
                    Assert.AreEqual(vector.output.ToUpper(), output[0].ToHex(), "Unexpected value in test #" + vector.n + ".");
                }

                foreach (TestVector vector in testvectors3)
                {
                    output = scenario.GetOutputs(new object[] { vector.input.HexToStream(), vector.key.HexToByteArray(), vector.mode });
                    Assert.AreEqual(vector.output.ToUpper(), output[0].ToHex(), "Unexpected value in test #" + vector.n + ".");
                }
            }
        }
示例#6
0
        public void ADFGVXTest()
        {
            var pluginInstance = TestHelpers.GetPluginInstance("ADFGVX");
            var scenario       = new PluginTestScenario(pluginInstance, new[] { ".CipherType", ".SubstitutionPass", ".TranspositionPass", "InputString" }, new[] { "OutputString" });

            //Test 1:
            if (!scenario.Test(new [] { (object)Cryptool.ADFGVX.ADFGVXSettings.CipherTypeEnum.ADFGX, "WIKPEDAZYXVUTSRQONMLHGFCB", "BEOBACHTUNGSLISTE", "Munitionierung beschleunigen Punkt Soweit nicht eingesehen auch bei Tag" }, new[] { "GXGGADDDGDXXAFADDFAAXAFDFFXFDGDXGAGGAAXFAGADFAAADGFAXXADADFFFDDADFGAXGXAFXGXFXDAFAGFXXFAXGFDXFFDFAGXXGXXADGXGFXDFFDGAXXFFFFGDX" }))
            {
                TestHelpers.TestFail(1);
            }
        }
示例#7
0
        public void RC4TestMethod()
        {
            var pluginInstance = TestHelpers.GetPluginInstance("RC4");
            var scenario       = new PluginTestScenario(pluginInstance, new[] { "InputData", "InputKey" }, new[] { "OutputStream" });

            foreach (TestVector vector in testvectors)
            {
                object[] output = scenario.GetOutputs(new object[] { (new byte[vector.offset + vector.output.Length / 2]).ToStream(), vector.key.HexToStream() });
                Assert.AreEqual(vector.output.ToUpper(), output[0].ToHex().Substring(vector.offset * 2), "Unexpected value in test #" + vector.n + ".");
            }
        }
示例#8
0
        public void DESTestMethod()
        {
            var pluginInstance = TestHelpers.GetPluginInstance("DES");
            var scenario       = new PluginTestScenario(pluginInstance, new[] { "InputStream", "InputIV", "InputKey", ".Action", ".Mode", ".Padding", ".TripleDES" }, new[] { "OutputStream" });

            foreach (TestVector vector in testvectors)
            {
                object[] output = scenario.GetOutputs(new object[] { vector.input.HexToStream(), vector.IV.HexToByteArray(), vector.key.HexToByteArray(), 0, 0, 0, vector.tdes });
                Assert.AreEqual(vector.output.ToUpper(), output[0].ToHex(), "Unexpected value in test #" + vector.n + ".");
            }
        }
示例#9
0
        public void MorseCodeTestMethod()
        {
            var pluginInstance = TestHelpers.GetPluginInstance("MorseCode");
            var scenario       = new PluginTestScenario(pluginInstance, new[] { "InputText", ".Action" }, new[] { "OutputText" });

            foreach (TestVector vector in testvectors)
            {
                object[] output = scenario.GetOutputs(new object[] { vector.input, vector.action });
                Assert.AreEqual(vector.output, output[0], "Unexpected value in test #" + vector.n + ".");
            }
        }
示例#10
0
        public void RIPEMD160TestMethod()
        {
            var pluginInstance = TestHelpers.GetPluginInstance("RIPEMD160");
            var scenario       = new PluginTestScenario(pluginInstance, new[] { "InputData" }, new[] { "OutputData" });

            foreach (TestVector vector in testvectors)
            {
                object[] output = scenario.GetOutputs(new object[] { vector.input.ToStream() });
                Assert.AreEqual(vector.output.ToUpper(), output[0].ToHex(), "Unexpected value in test #" + vector.n + ".");
            }
        }
示例#11
0
        public void TranspositionTestMethod()
        {
            var pluginInstance = TestHelpers.GetPluginInstance("Transposition");
            var scenario       = new PluginTestScenario(pluginInstance, new[] { "Input", "Keyword", ".ReadIn", ".Permutation", ".ReadOut" }, new[] { "Output" });

            object[] output;

            foreach (TestVector vector in testvectors)
            {
                output = scenario.GetOutputs(new object[] { vector.input.ToStream(), vector.key, vector.readin, vector.perm, vector.readout });
                Assert.AreEqual(vector.output, ((ICryptoolStream)output[0]).ToByteArray().ToString2(), "Unexpected value in test #" + vector.n + ".");
            }
        }
示例#12
0
        public void ADFGVXTestMethod()
        {
            var pluginInstance = TestHelpers.GetPluginInstance("ADFGVX");
            var scenario       = new PluginTestScenario(pluginInstance, new[] { "InputString", ".CipherType", ".SubstitutionPass", ".TranspositionPass" }, new[] { "OutputString" });

            object[] output;

            foreach (TestVector vector in testvectors)
            {
                output = scenario.GetOutputs(new object[] { vector.input, vector.cipher, vector.subkey, vector.transkey });
                Assert.AreEqual(vector.output, (string)output[0], "Unexpected value in test #" + vector.n + ".");
            }
        }
示例#13
0
        public void PlayfairTestMethod()
        {
            var pluginInstance = TestHelpers.GetPluginInstance("Playfair");
            var scenario       = new PluginTestScenario(pluginInstance, new[] { "InputString", ".Key", ".MatrixSize" }, new[] { "OutputString" });

            object[] output;

            foreach (TestVector vector in testvectors)
            {
                output = scenario.GetOutputs(new object[] { vector.input, vector.key, vector.size });
                Assert.AreEqual(vector.output, (string)output[0], "Unexpected value in test #" + vector.n + ".");
            }
        }
示例#14
0
        public void CaesarTestMethod()
        {
            var pluginInstance = TestHelpers.GetPluginInstance("Caesar");
            var scenario       = new PluginTestScenario(pluginInstance, new[] { "InputString", "InputAlphabet", "ShiftKey", ".CaseSensitive" }, new[] { "OutputString" });

            object[] output;

            foreach (TestVector vector in testvectors)
            {
                output = scenario.GetOutputs(new object[] { vector.input, vector.alphabet, vector.key, vector.sensitivity });
                Assert.AreEqual(vector.output, (string)output[0], "Unexpected value in test #" + vector.n + ".");
            }
        }
示例#15
0
        public void VernamTestMethod()
        {
            var pluginInstance = TestHelpers.GetPluginInstance("Vernam");
            var scenario       = new PluginTestScenario(pluginInstance, new[] { "InputString", "KeyString", "CipherMode", "UnknownSymbolHandling" }, new[] { "OutputString" });

            object[] output;

            foreach (TestVector vector in testvectors)
            {
                output = scenario.GetOutputs(new object[] { vector.input, vector.key, vector.cipherMode, vector.UnknownSymbolHandling });
                Assert.AreEqual(vector.output, (string)output[0], "Unexpected value in test #" + vector.n + ".");
            }
        }
示例#16
0
        public void VigenereTestMethod()
        {
            var pluginInstance = TestHelpers.GetPluginInstance("Vigenere");
            var scenario       = new PluginTestScenario(pluginInstance, new[] { "InputString", "ShiftValue" }, new[] { "OutputString" });

            object[] output;

            foreach (TestVector vector in testvectors)
            {
                output = scenario.GetOutputs(new object[] { vector.input, vector.key });
                Assert.AreEqual(vector.output, (string)output[0], "Unexpected value in test #" + vector.n + ".");
            }
        }
示例#17
0
        public void ScytaleTestMethod()
        {
            var pluginInstance = TestHelpers.GetPluginInstance("Scytale");
            var scenario       = new PluginTestScenario(pluginInstance, new[] { "InputString", "StickSize", ".Action" }, new[] { "OutputString" });

            object[] output;

            foreach (TestVector vector in testvectors)
            {
                output = scenario.GetOutputs(new object[] { vector.input, vector.size, vector.action });
                Assert.AreEqual(vector.output, (string)output[0], "Unexpected value in test #" + vector.n + ".");
            }
        }
示例#18
0
        public void NihilistTestMethod()
        {
            var pluginInstance = TestHelpers.GetPluginInstance("Nihilist");
            var scenario       = new PluginTestScenario(pluginInstance, new[] { "Input", ".KeyWord", ".SecondKeyWord" }, new[] { "Output" });

            object[] output;

            foreach (TestVector vector in testvectors)
            {
                output = scenario.GetOutputs(new object[] { vector.input.ToByteArray(), vector.key1, vector.key2 });
                Assert.AreEqual(vector.output, ((byte[])output[0]).ToHex(), "Unexpected value in test #" + vector.n + ".");
            }
        }
示例#19
0
        public void EnigmaTestMethod()
        {
            var pluginInstance = TestHelpers.GetPluginInstance("Enigma");
            var scenario       = new PluginTestScenario(pluginInstance, new[] { "InputString", ".Model", ".Key", ".Rotor1", ".Rotor2", ".Rotor3", ".Rotor4", ".Reflector", ".Ring1", ".Ring2", ".Ring3", ".Ring4", ".PlugBoard" }, new[] { "OutputString" });

            object[] output;

            foreach (TestVector vector in testvectors)
            {
                output = scenario.GetOutputs(new object[] { vector.input, vector.model, vector.key, vector.rot1, vector.rot2, vector.rot3, vector.rot4, vector.ukw, vector.ring1, vector.ring2, vector.ring3, vector.ring4, vector.plugBoard }, false);
                Assert.AreEqual(vector.output.ToUpper(), (string)output[0], "Unexpected value in test #" + vector.n + ".");
            }
        }
示例#20
0
        private void RunTests(TestVector[] vectors)
        {
            var pluginInstance = TestHelpers.GetPluginInstance("ChaCha");
            // We use .VersionIndex instead of .Version because else we would need to include the ChaCha namespace since we need to use the Version type.
            // With .VersionIndex, we can simply use integers to set the version.
            var scenario = new PluginTestScenario(pluginInstance, new[] { "InputStream", "InputKey", "InputIV", "InitialCounter", ".Rounds", ".VersionIndex" }, new[] { "OutputStream" });

            foreach (TestVector vector in vectors)
            {
                object[] output        = scenario.GetOutputs(new object[] { vector.input.HexToStream(), vector.key.HexToByteArray(), vector.iv.HexToByteArray(), vector.initialCounter, vector.rounds, vector.version });
                string   versionString = vector.version == 0 ? "DJB" : "IETF";
                Assert.AreEqual(vector.output.ToUpper(), output[0].ToHex().ToUpper(), string.Format("Unexpected value in test #{0} for ChaCha {1} version.", vector.n, versionString));
            }
        }
示例#21
0
        public void StegoLSBTestMethod()
        {
            var pluginInstance = TestHelpers.GetPluginInstance("StegoLeastSignificantBit");
            var scenario       = new PluginTestScenario(pluginInstance, new[] { "InputData", "InputCarrier", "InputPassword", ".Action", ".CustomizeRegions", ".OutputFileFormat" }, new[] { "OutputData", "OutputCarrier" });

            CStreamWriter carrierImage = new CStreamWriter("..\\..\\Templates\\Steganography\\cryptool2.jpg", true);

            foreach (TestVector vector in testvectors)
            {
                object[] output1 = scenario.GetOutputs(new object[] { vector.message.ToStream(), carrierImage, vector.password.ToStream(), 0, false, 1 });
                object[] output2 = scenario.GetOutputs(new object[] { null, (ICryptoolStream)output1[1], vector.password.ToStream(), 1, false, 1 });
                // check if hiding and extracting the secret message leaves it unchanged
                Assert.AreEqual(vector.message, ((ICryptoolStream)output2[0]).ToByteArray().ToString2(), "Unexpected value in test #" + vector.n + ".");
            }
        }
示例#22
0
        public void CasearTest()
        {
            var pluginInstance = TestHelpers.GetPluginInstance("Caesar");
            var scenario       = new PluginTestScenario(pluginInstance, new[] { "ShiftKey", "InputAlphabet", "InputString", ".CaseSensitive" }, new[] { "OutputString" });

            //Test 1:
            if (!scenario.Test(new object[] { 24, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "Franz jagt im komplett verwahrlosten Taxi quer durch Bayern", false }, new[] { "Dpylx hyer gk imknjcrr tcpuyfpjmqrcl Ryvg oscp bspaf Zywcpl".ToUpper() }))
            {
                TestHelpers.TestFail(1);
            }

            //Test 2:
            if (!scenario.Test(new object[] { 24, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", "Franz jagt im komplett verwahrlosten Taxi quer durch Bayern", true }, new[] { "dPyLX HyER GK IMKNJCRR TCPUyFPJMQRCL ryVG OSCP BSPAF ZyWCPL" }))
            {
                TestHelpers.TestFail(2);
            }
        }
示例#23
0
        public void PurpleTestMethod()
        {
            var pluginInstance = TestHelpers.GetPluginInstance("Purple");
            var scenario       = new PluginTestScenario(pluginInstance, new[] { "Text", ".Action", ".Alphabet", ".Motion", ".Sixes", ".Twenties", ".Twenties2", ".Twenties3", ".UnknownSymbolHandling", ".CaseHandling", ".OutputFormatting" }, new[] { "OutputString" });

            object[] output;

            foreach (TestVector vector in testvectors)
            {
                // encrypt
                output = scenario.GetOutputs(new object[] { vector.input, 0, vector.alphabet, vector.motion, vector.sixes, vector.twenties, vector.twenties2, vector.twenties3, vector.unknownSymbolHandling, vector.caseHandling, vector.outputFormatting });
                Assert.AreEqual(vector.output.ToUpper(), output[0], "Unexpected value in test #" + vector.n + ".");
                // decrypt
                output = scenario.GetOutputs(new object[] { vector.output, 1, vector.alphabet, vector.motion, vector.sixes, vector.twenties, vector.twenties2, vector.twenties3, vector.unknownSymbolHandling, vector.caseHandling, vector.outputFormatting });
                Assert.AreEqual(vector.input.ToUpper(), output[0], "Unexpected value in test #" + vector.n + ".");
            }
        }
示例#24
0
        public void TigerTestMethod()
        {
            var pluginInstance = TestHelpers.GetPluginInstance("Tiger");

            // Parameters as ByteArrays
            var scenario = new PluginTestScenario(pluginInstance, new[] { "InputData" }, new[] { "HashOutputData" });

            foreach (TestVector vector in testvectors)
            {
                object[] output = scenario.GetOutputs(new object[] { vector.input.ToByteArray() });
                Assert.AreEqual(vector.output.ToUpper(), output[0].ToHex(), "Unexpected value in test #" + vector.n + ".");
            }

            // Parameters as Streams
            scenario = new PluginTestScenario(pluginInstance, new[] { "InputStream" }, new[] { "HashOutputStream" });

            foreach (TestVector vector in testvectors)
            {
                object[] output = scenario.GetOutputs(new object[] { vector.input.ToStream() });
                Assert.AreEqual(vector.output.ToUpper(), output[0].ToHex(), "Unexpected value in test #" + vector.n + ".");
            }
        }
示例#25
0
        public void PrimesGeneratorTestMethod()
        {
            var pluginInstance = TestHelpers.GetPluginInstance("PrimesGenerator");
            var scenario       = new PluginTestScenario(pluginInstance, new[] { "n", ".Mode" }, new[] { "OutputString" });

            foreach (TestVector vector in testvectors)
            {
                if (vector.mode <= 2)
                {
                    for (int i = 0; i < vector.count; i++)
                    {
                        object[] output = scenario.GetOutputs(new object[] { vector.input, vector.mode });
                        Assert.IsTrue(BigIntegerHelper.IsProbablePrime((BigInteger)output[0]), (BigInteger)output[0] + " is not a prime number in test #" + vector.n + ".");
                    }
                }
                else
                {
                    object[] output = scenario.GetOutputs(new object[] { vector.input, vector.mode });
                    Assert.AreEqual(vector.output, output[0], "Unexpected value in test #" + vector.n + ".");
                }
            }
        }
示例#26
0
        public void MD5TestMethod()
        {
            var pluginInstance = TestHelpers.GetPluginInstance("MD5");
            var scenario1      = new PluginTestScenario(pluginInstance, new[] { "InputData" }, new[] { "OutputDataStream" });
            var scenario2      = new PluginTestScenario(pluginInstance, new[] { "InputData" }, new[] { "OutputData" });

            object[] output;

            foreach (TestVector vector in testvectors)
            {
                output = scenario1.GetOutputs(new object[] { vector.input.ToStream() });
                Assert.AreEqual(vector.output.ToUpper(), output[0].ToHex(), "Unexpected value in test #" + vector.n + ".");
                output = scenario2.GetOutputs(new object[] { vector.input.ToStream() });
                Assert.AreEqual(vector.output.ToUpper(), output[0].ToHex(), "Unexpected value in test #" + vector.n + ".");
            }

            ICryptoolStream input = new String('\0', 16).ToStream();

            for (int i = 0; i < 100000; i++)
            {
                input = (ICryptoolStream)scenario1.GetOutputs(new object[] { input })[0];
            }
            Assert.AreEqual("1A83F51285E4D89403D00C46EF8508FE", input.ToHex(), "Unexpected value in iteration test");
        }