Exemplo n.º 1
0
        public void Multigraph_RailFenceTest()
        {
            RailFence railfence = new RailFence(Utility.KeyedEnglishAlphabet("KRYPTOS").ToStringArray());

            byte[] tokenData = new byte[2];
            using (System.Security.Cryptography.RandomNumberGenerator rng = new System.Security.Cryptography.RNGCryptoServiceProvider())
            {
                rng.GetBytes(tokenData);

                railfence.Key = (int)(BitConverter.ToUInt16(tokenData, 0) >> 8);

                for (int i = 0; i < 25; i++)
                {
                    generated = railfence.GenerateRandomLetters();

                    cipher = railfence.Encrypt(generated);
                    clear  = railfence.Decrypt(cipher);

                    CollectionAssert.AreEqual(generated, clear);
                }
            }
        }