예제 #1
0
        private static void Encrypt()
        {
            var ice = new IceKey(2);

            ice.Set(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 });

            using (var reader = new BinaryReader(File.OpenRead("plain.txt")))
            {
                byte[] temp      = new byte[reader.BaseStream.Length];
                int    bytesLeft = (int)reader.BaseStream.Length;
                while (bytesLeft >= 8)
                {
                    byte[] tmp    = new byte[8];
                    byte[] buffer = reader.ReadBytes(8);
                    ice.Encrypt(buffer, ref tmp);
                    bytesLeft -= 8;
                    Array.Copy(tmp, temp, 8);
                }
                File.WriteAllBytes("out.ice", temp);
            }
        }
예제 #2
0
        private static void DecipherPayload(byte[] payload)
        {
            var ice = new IceKey(2);

            ice.Set(iceKey);

            var blockSize       = ice.BlockSize();
            var ciphertextBlock = new byte[blockSize];
            var plaintextBlock  = new byte[blockSize];

            using (var plaintext = new MemoryStream(payload.Length))
            {
                using (var ciphertext = new MemoryStream(payload))
                {
                    while (true)
                    {
                        var bytesRead = ciphertext.Read(ciphertextBlock, 0, blockSize);
                        if (bytesRead < blockSize)
                        {
                            // The end is not ciphered !?!?
                            plaintext.Write(ciphertextBlock, 0, bytesRead);
                            break;
                        }

                        ice.Decrypt(ciphertextBlock, ref plaintextBlock);
                        plaintext.Write(plaintextBlock, 0, blockSize);
                    }
                }

                plaintext.Seek(0, SeekOrigin.Begin);

                var plaintextData = plaintext.ToArray();

                GetOnlyValidMsg(plaintextData, payload.Length);
            }
        }