Exemplo n.º 1
0
        private void VectorTest(byte[] Key, byte[] Input, byte[] Output)
        {
            byte[] outBytes = new byte[Input.Length];

            using (TFX tfx = new TFX())
            {
                tfx.Initialize(true, new KeyParams(Key));
                tfx.EncryptBlock(Input, outBytes);
            }

            if (Compare.AreEqual(outBytes, Output) == false)
                throw new Exception("Twofish Vector: Encrypted arrays are not equal! Expected: " + HexConverter.ToString(Output) + " Received: " + HexConverter.ToString(outBytes));

            using (TFX tfx = new TFX())
            {
                tfx.Initialize(false, new KeyParams(Key));
                tfx.Transform(Output, outBytes);
            }

            if (Compare.AreEqual(outBytes, Input) == false)
                throw new Exception("Twofish Vector: Decrypted arrays are not equal! Expected: " + HexConverter.ToString(Input) + " Received: " + HexConverter.ToString(outBytes));
        }
Exemplo n.º 2
0
        private void MonteCarloTest(byte[] Key, byte[] Input, byte[] Output, bool Encrypt = true, int Count = 10000)
        {
            byte[] outBytes = new byte[Input.Length];
            Array.Copy(Input, 0, outBytes, 0, outBytes.Length);

            using (TFX engine = new TFX())
            {
                engine.Initialize(Encrypt, new KeyParams(Key));

                for (int i = 0; i < Count; i++)
                    engine.Transform(outBytes, outBytes);
            }

            if (Compare.AreEqual(outBytes, Output) == false)
                throw new Exception("Twofish MonteCarlo: Arrays are not equal! Expected: " + HexConverter.ToString(Output) + " Received: " + HexConverter.ToString(outBytes));
        }