예제 #1
0
파일: Program.cs 프로젝트: grw300/RC4
        public static void Main(string[] args)
        {
            Console.OutputEncoding = Encoding.Unicode;

            byte[] key = { 1, 2, 3, 4, 5 };

            var dataText = @"Hello Greg!";
            var data     = Encoding.Unicode.GetBytes(dataText);

            var cipher     = RC4.Encrypt(key, data);
            var cipherText = Encoding.Unicode.GetString(cipher.ToArray());

            var retrieved     = RC4.Decrypt(key, cipher);
            var retrievedText = Encoding.Unicode.GetString(retrieved.ToArray());

            Console.WriteLine($"Data text     : {dataText}");
            Console.WriteLine($"Cipher text   : {cipherText}");
            Console.WriteLine($"Cipher bytes   : {PrintByteArray(cipher.ToArray())}");
            Console.WriteLine($"Retrieved text: {retrievedText}");

            Console.WriteLine($"Period of first pseudo-random byte: {RC4.GetKeyInitializationPeriod(key, 1)}");
            Console.WriteLine($"Period of second pseudo-random byte: {RC4.GetKeyInitializationPeriod(key, 2)}");

            Console.ReadKey();
        }