Ejemplo n.º 1
0
        public static void Main(string[] args)
        {
            RabbitCipher rc = new RabbitCipher();

            //test all accessible features>>
            Console.WriteLine(rc.BitsEncryptedPerIteration.ToString());
            Console.WriteLine("\n\n" + rc.BlockSize.ToString());
            Console.WriteLine("\n\n" + rc.IVBitSize.ToString());
            Console.WriteLine("\n\n" + rc.LegalBlockSizes.ToString());
            Console.WriteLine("\n\n" + rc.LegalKeySizes.ToString());
            Console.WriteLine("\n\n" + rc.KeySize.ToString());
            //test exception catchers
            rc.IV  = Encoding.ASCII.GetBytes("TESTFOR");            //should throw an error;
            rc.Key = Encoding.ASCII.GetBytes("ERRORRIGHTHERE");     //should throw an error
            rc.CheckIV(rc.IV);
            rc.CheckKey(rc.Key);
            Console.Write("\n\nPress any key to continue . . . ");
            Console.ReadKey(true);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("Syntax: EncryptFile.exe <input-file> <output-file>");
                Console.WriteLine("  For decryption, swap input and output file");
                return;
            }

            byte[] key = new byte[]
            {
                0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x6, 0x7,
                0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0xE, 0xF
            };

            ICryptoTransform cipher = RabbitCipher.CreateEncryptor(key);

            byte[] buffer = new byte[10000];

            Stopwatch sw = new Stopwatch();

            sw.Start();

            using (FileStream infs = new FileStream(args[0], FileMode.Open, FileAccess.Read))
                using (FileStream outfs = new FileStream(args[1], FileMode.Create, FileAccess.Write))
                    using (CryptoStream cs = new CryptoStream(outfs, cipher, CryptoStreamMode.Write))
                    {
                        while (true)
                        {
                            int r = infs.Read(buffer, 0, buffer.Length);
                            if (r <= 0)
                            {
                                break;
                            }
                            cs.Write(buffer, 0, r);
                        }
                    }

            sw.Stop();
            Console.WriteLine($"Elapsed time: {sw.ElapsedMilliseconds} ms");
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            byte[] key = new byte[]
            {
                0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x6, 0x7,
                0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0xE, 0xF
            };

            string plainText = "The quick brown fox jumps over the lazy dog";

            byte[] plainBytes = Encoding.UTF8.GetBytes(plainText);

            // Encoding

            RabbitCipher rabbit = new RabbitCipher(key);

            byte[] encoded = new byte[plainBytes.Length];

            for (int j = 0; j < plainBytes.Length; j++)
            {
                encoded[j] = rabbit.CipherByte(plainBytes[j]);
            }

            // Decoding

            RabbitCipher rabbit2 = new RabbitCipher(key);

            byte[] decoded = new byte[encoded.Length];

            for (int j = 0; j < encoded.Length; j++)
            {
                decoded[j] = rabbit2.CipherByte(encoded[j]);
            }

            Console.WriteLine($"Plain  : {plainText}");
            Console.WriteLine($"Encoded: {Encoding.UTF8.GetString(encoded)}");
            Console.WriteLine($"Decoded: {Encoding.UTF8.GetString(decoded)}");
        }
Ejemplo n.º 4
0
        public void Test_A1_2()
        {
            byte[] key = StringToByteArray("91 28 13 29 2E 3D 36 FE 3B FC 62 F1 DC 51 C3 AC");

            RabbitCipher rabbit = new RabbitCipher(key);

            byte[] state_0 = StringToByteArray("3D 2D F3 C8 3E F6 27 A1 E9 7F C3 84 87 E2 51 9C");
            byte[] state_1 = StringToByteArray("F5 76 CD 61 F4 40 5B 88 96 BF 53 AA 85 54 FC 19");
            byte[] state_2 = StringToByteArray("E5 54 74 73 FB DB 43 50 8A E5 3B 20 20 4D 4C 5E");

            rabbit.Round();
            byte[] S0 = rabbit.GetState();
            AssertEqual(S0, state_0);

            rabbit.Round();
            byte[] S1 = rabbit.GetState();
            AssertEqual(S1, state_1);

            rabbit.Round();
            byte[] S2 = rabbit.GetState();
            AssertEqual(S2, state_2);

            Console.WriteLine("Test A1/2 successful");
        }
Ejemplo n.º 5
0
        public void Test_A1_1()
        {
            byte[] key = StringToByteArray("00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00");

            RabbitCipher rabbit = new RabbitCipher(key);

            byte[] state_0 = StringToByteArray("B1 57 54 F0 36 A5 D6 EC F5 6B 45 26 1C 4A F7 02");
            byte[] state_1 = StringToByteArray("88 E8 D8 15 C5 9C 0C 39 7B 69 6C 47 89 C6 8A A7");
            byte[] state_2 = StringToByteArray("F4 16 A1 C3 70 0C D4 51 DA 68 D1 88 16 73 D6 96");

            rabbit.Round();
            byte[] S0 = rabbit.GetState();
            AssertEqual(S0, state_0);

            rabbit.Round();
            byte[] S1 = rabbit.GetState();
            AssertEqual(S1, state_1);

            rabbit.Round();
            byte[] S2 = rabbit.GetState();
            AssertEqual(S2, state_2);

            Console.WriteLine("Test A1/1 successful");
        }
Ejemplo n.º 6
0
        public void Test_A2_3()
        {
            byte[] key     = StringToByteArray("00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00");
            byte[] iv      = StringToByteArray("A6 EB 56 1A D2 F4 17 27");
            byte[] state_0 = StringToByteArray("44 5A D8 C8 05 85 8D BF 70 B6 AF 23 A1 51 10 4D");
            byte[] state_1 = StringToByteArray("96 C8 F2 79 47 F4 2C 5B AE AE 67 C6 AC C3 5B 03");
            byte[] state_2 = StringToByteArray("9F CB FC 89 5F A7 1C 17 31 3D F0 34 F0 15 51 CB");

            RabbitCipher rabbit = RabbitCipher.Create(key, iv);

            rabbit.Round();
            byte[] S0 = rabbit.GetState();
            AssertEqual(state_0, S0);

            rabbit.Round();
            byte[] S1 = rabbit.GetState();
            AssertEqual(state_1, S1);

            rabbit.Round();
            byte[] S2 = rabbit.GetState();
            AssertEqual(state_2, S2);

            Console.WriteLine("Test A2/3 successful");
        }
Ejemplo n.º 7
0
        public void Test_A2_2()
        {
            byte[] key     = StringToByteArray("00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00");
            byte[] iv      = StringToByteArray("C3 73 F5 75 C1 26 7E 59");
            byte[] state_0 = StringToByteArray("1F CD 4E B9 58 00 12 E2 E0 DC CC 92 22 01 7D 6D");
            byte[] state_1 = StringToByteArray("A7 5F 4E 10 D1 21 25 01 7B 24 99 FF ED 93 6F 2E");
            byte[] state_2 = StringToByteArray("EB C1 12 C3 93 E7 38 39 23 56 BD D0 12 02 9B A7");

            RabbitCipher rabbit = RabbitCipher.Create(key, iv);

            rabbit.Round();
            byte[] S0 = rabbit.GetState();
            AssertEqual(state_0, S0);

            rabbit.Round();
            byte[] S1 = rabbit.GetState();
            AssertEqual(state_1, S1);

            rabbit.Round();
            byte[] S2 = rabbit.GetState();
            AssertEqual(state_2, S2);

            Console.WriteLine("Test A2/2 successful");
        }
Ejemplo n.º 8
0
        public void Test_A2_1()
        {
            byte[] key     = StringToByteArray("00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00");
            byte[] iv      = StringToByteArray("00 00 00 00 00 00 00 00");
            byte[] state_0 = StringToByteArray("C6 A7 27 5E F8 54 95 D8 7C CD 5D 37 67 05 B7 ED");
            byte[] state_1 = StringToByteArray("5F 29 A6 AC 04 F5 EF D4 7B 8F 29 32 70 DC 4A 8D");
            byte[] state_2 = StringToByteArray("2A DE 82 2B 29 DE 6C 1E E5 2B DB 8A 47 BF 8F 66");

            RabbitCipher rabbit = RabbitCipher.Create(key, iv);

            rabbit.Round();
            byte[] S0 = rabbit.GetState();
            AssertEqual(state_0, S0);

            rabbit.Round();
            byte[] S1 = rabbit.GetState();
            AssertEqual(state_1, S1);

            rabbit.Round();
            byte[] S2 = rabbit.GetState();
            AssertEqual(state_2, S2);

            Console.WriteLine("Test A2/1 successful");
        }
Ejemplo n.º 9
0
        public void Test_A1_3()
        {
            byte[] key = StringToByteArray("83 95 74 15 87 E0 C7 33 E9 E9 AB 01 C0 9B 00 43");

            RabbitCipher rabbit = new RabbitCipher(key);

            byte[] state_0 = StringToByteArray("0C B1 0D CD A0 41 CD AC 32 EB 5C FD 02 D0 60 9B");
            byte[] state_1 = StringToByteArray("95 FC 9F CA 0F 17 01 5A 7B 70 92 11 4C FF 3E AD");
            byte[] state_2 = StringToByteArray("96 49 E5 DE 8B FC 7F 3F 92 41 47 AD 3A 94 74 28");

            rabbit.Round();
            byte[] S0 = rabbit.GetState();
            AssertEqual(S0, state_0);

            rabbit.Round();
            byte[] S1 = rabbit.GetState();
            AssertEqual(S1, state_1);

            rabbit.Round();
            byte[] S2 = rabbit.GetState();
            AssertEqual(S2, state_2);

            Console.WriteLine("Test A1/3 successful");
        }
        private void MainTest()
        {
            RabbitCipher rc = new RabbitCipher(); //initialize

            //generate IV And Key to be Used
            rc.GenerateIV();
            rc.GenerateKey();
            //----------------------------<<

            //begin encrypting
            try
            {
                using (SymmetricAlgorithm RabbitCipher = new RabbitCipher())
                    using (ICryptoTransform transform = RabbitCipher.CreateEncryptor(rc.Key, rc.IV))
                    {
                        byte[] test_file = new byte[7675];             //not an actual file
                        byte[] output    = new byte[test_file.Length]; //encyption does not change file size
                        if (test_file.Length % 16 != 0)                //encrypts in bytes of 16 so if it is not perfectly made of 16 blocks we will need to transform the final block
                        {
                            int encrypted_bytes = transform.TransformBlock(test_file, 0, test_file.Length, output, 0);
                            //now the data is all encrypted in the output byte[] array
                        }
                        else
                        {
                            int encrypted_bytes = transform.TransformBlock(test_file, 0, test_file.Length, output, 0);
                            //now the data is all encrypted in the output byte[] array
                        }
                    }
            }
            catch (Exception ex)
            {
                Console.WriteLine("\nThere was An Error When Encrypting <> Error Code:\n\n" + ex.ToString());
            }
            //------------------<<

            //begin Decrypting
            try
            {
                using (SymmetricAlgorithm RabbitCipher = new RabbitCipher())
                    using (ICryptoTransform transform = RabbitCipher.CreateDecryptor(rc.Key, rc.IV))
                    {
                        byte[] encrypted_data = new byte[4343];
                        byte[] plaintext_data = new byte[encrypted_data.Length];
                        if (encrypted_data.Length % 16 != 0)
                        {
                            int decrypted_bytes = transform.TransformBlock(encrypted_data, 0, encrypted_data.Length, plaintext_data, 0);
                            //now decrypted
                        }
                        else
                        {
                            transform.TransformBlock(encrypted_data, 0, encrypted_data.Length, plaintext_data, 0);
                            //now decrypted
                        }
                    }
            }
            catch (Exception ex)
            {
                Console.WriteLine("\nThere was An Error When Decrypting <> Error Code:\n\n" + ex.ToString());
            }
            //------------------<<
        }