예제 #1
0
        /// <summary>
        ///     executes a selftest
        /// </summary>
        /// <remarks>
        ///     Call this method to make sure that the instance is able to produce
        ///     valid output according to the specification.
        /// </remarks>
        /// <returns>
        ///     true: selftest passed / false: selftest failed
        /// </returns>
        public static bool SelfTest()
        {
            var unHi = TEST_VECTOR_PLAIN[0];
            var unLo = TEST_VECTOR_PLAIN[1];

            var bf = new BlowfishBase(TEST_KEY);

            bf.Encrypt(ref unHi, ref unLo);

            if ((unHi != TEST_VECTOR_CIPHER[0]) ||
                (unLo != TEST_VECTOR_CIPHER[1]))
            {
                return false;
            }

            bf.Decrypt(ref unHi, ref unLo);

            if ((unHi != TEST_VECTOR_PLAIN[0]) ||
                (unLo != TEST_VECTOR_PLAIN[1]))
            {
                return false;
            }

            return true;
        }