Exemple #1
0
        public void RunScenario(IEncoder encoder)
        {
            byte[] key;
            byte[] text = BlockProvider.ZeroBlock(textSize);

            if (mode == Mode.Key)
            {
                key  = BlockProvider.HemmingBlock(keySize, hemming);
                text = BlockProvider.RandomBlock(textSize);
            }
            else
            {
                key = BlockProvider.RandomBlock(keySize);

                byte[] X;

                int rounds = textSize / blockLength;

                for (int i = 0; i < rounds; i++)
                {
                    X = BlockProvider.HemmingBlock(blockLength, hemming);
                    Buffer.BlockCopy(X, 0, text, i * blockLength, blockLength);
                }

                text = BlockProvider.HemmingBlock(textSize, hemming);
            }

            encoder.SetupKey(key);
            byte[] cipherText = encoder.Encrypt(text);

            TestSuiteRunner runner = new TestSuiteRunner();

            runner.RunSuite(cipherText);
        }
        public void RunScenario(IEncoder encoder)
        {
            byte[] text = BlockProvider.ZeroBlock(textSize);
            byte[] key  = BlockProvider.RandomBlock(keySize);

            encoder.SetupKey(key);

            int rounds = textSize / blockLength;

            for (int i = 0; i < rounds; i++)
            {
                byte[] X = BlockProvider.RandomBlock(blockLength);
                BlowfishEncoder.XOR(ref X, encoder.Encrypt(X));
                Buffer.BlockCopy(X, 0, text, i * blockLength, blockLength);
            }

            TestSuiteRunner runner = new TestSuiteRunner();

            runner.RunSuite(text);
        }
        public void RunScenario(IEncoder encoder)
        {
            byte[] text = BlockProvider.ZeroBlock(textSize);
            byte[] key;

            byte[] X;

            int rounds       = textSize / (keySize * 8 * blockLength);
            int textPosition = 0;

            for (int i = 0; i < rounds; i++)
            {
                key = BlockProvider.RandomBlock(keySize);
                X   = BlockProvider.ZeroBlock(blockLength);

                encoder.SetupKey(key);
                byte[] F = encoder.Encrypt(X);

                for (int j = 0; j < keySize * 8; j++)
                {
                    List <int> bits = BinaryConverter.ToBinaryList(key);
                    bits[j] = bits[j] == 1 ? 0 : 1;

                    byte[] Ki = BinaryConverter.ToByteArray(bits);
                    encoder.SetupKey(Ki);

                    byte[] Fi = encoder.Encrypt(X);
                    BlowfishEncoder.XOR(ref Fi, F);

                    Buffer.BlockCopy(Fi, 0, text, textPosition, blockLength);
                    textPosition += 8;
                }
            }

            TestSuiteRunner runner = new TestSuiteRunner();

            runner.RunSuite(text);
        }