private void VectorTest(byte[] Key, byte[] Input, byte[] Output) { byte[] outBytes = new byte[Input.Length]; using (THX tfx = new THX()) { tfx.Initialize(true, new KeyParams(Key)); tfx.EncryptBlock(Input, outBytes); } if (Evaluate.AreEqual(outBytes, Output) == false) { throw new Exception("Twofish Vector: Encrypted arrays are not equal! Expected: " + HexConverter.ToString(Output) + " Received: " + HexConverter.ToString(outBytes)); } using (THX tfx = new THX()) { tfx.Initialize(false, new KeyParams(Key)); tfx.Transform(Output, outBytes); } if (Evaluate.AreEqual(outBytes, Input) == false) { throw new Exception("Twofish Vector: Decrypted arrays are not equal! Expected: " + HexConverter.ToString(Input) + " Received: " + HexConverter.ToString(outBytes)); } }
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 (THX engine = new THX()) { engine.Initialize(Encrypt, new KeyParams(Key)); for (int i = 0; i < Count; i++) { engine.Transform(outBytes, outBytes); } } if (Evaluate.AreEqual(outBytes, Output) == false) { throw new Exception("Twofish MonteCarlo: Arrays are not equal! Expected: " + HexConverter.ToString(Output) + " Received: " + HexConverter.ToString(outBytes)); } }