Exemplo n.º 1
0
        public override void Decrypt(FileInfo input, FileInfo output)
        {
            FileStream inputStream  = input.OpenRead();
            FileStream outputStream = output.OpenWrite();

            int[]  code  = Key.Code();
            byte[] bytes = new byte[code.Length];

            long i  = 0;
            int  mx = 0;

            while (i < inputStream.Length)
            {
                mx = code.Length;
                if (inputStream.Length - i < mx)
                {
                    mx = (int)(inputStream.Length - i);
                }
                inputStream.Read(bytes, 0, mx);
                for (int j = 0; j < mx; j++)
                {
                    bytes[j] = (byte)ChangeByte(bytes[j], -code[j]);
                    i++;
                    CustomProgressBar.update((int)((i) * 100 / inputStream.Length));
                }
                outputStream.Write(bytes, 0, mx);
            }

            inputStream.Close();
            outputStream.Close();
        }
Exemplo n.º 2
0
        public SuccessBox(string msg)
        {
            DialogResult result = MessageBox.Show(msg,
                                                  "Успешно",
                                                  MessageBoxButtons.OK,
                                                  MessageBoxIcon.None);

            if (result == DialogResult.OK)
            {
                CustomProgressBar.update(0);
            }
        }
Exemplo n.º 3
0
        public override void Encrypt(FileInfo input, FileInfo output)
        {
            if (key == null)
            {
                Console.WriteLine("Hard key is null");
                return;
            }

            FileStream inputStream  = input.OpenRead();
            FileStream outputStream = output.OpenWrite();

            int j = 0;

            Random rnd = new Random();

            long i = 0;

            while (j < key.MaxBadBytes)
            {
                int bd = key.getBadByte(j);

                CustomProgressBar.update((int)(j * 50 / key.MaxBadBytes));

                if (j == 0 || (bd - key.getBadByte(j - 1)) == 1)
                {
                    outputStream.WriteByte((byte)rnd.Next(1, 256));
                    j++;
                    continue;
                }

                for (bd--; bd > key.getBadByte(j - 1); bd--)
                {
                    Console.WriteLine(key.getCurByte((int)(i % key.MaxCryptoLength)));
                    outputStream.WriteByte((byte)ChangeByte(inputStream.ReadByte(), key.getCurByte((int)(i % key.MaxCryptoLength))));
                    Console.WriteLine("Printed at " + i + " " + j);
                    i++;
                }

                outputStream.WriteByte((byte)rnd.Next(1, 256));
                j++;
            }

            for (; i < inputStream.Length; i++)
            {
                CustomProgressBar.update(50 + (int)(i * 50 / inputStream.Length));

                outputStream.WriteByte((byte)ChangeByte(inputStream.ReadByte(), key.getCurByte((int)(i % key.MaxCryptoLength))));
            }

            inputStream.Close();
            outputStream.Close();
        }
Exemplo n.º 4
0
        public override void Decrypt(FileInfo input, FileInfo output)
        {
            if (key == null)
            {
                Console.WriteLine("Hard key is null");
                return;
            }

            FileStream inputStream  = input.OpenRead();
            FileStream outputStream = output.OpenWrite();

            int j = 0;

            long ks = 0;
            //todo переписать весь блок под чтение по байтам в одном цикле
            int bd = 0;

            for (long i = 0; i < inputStream.Length; i++)
            {
                //if(j < key.MaxBadBytes) bd = key.getBadByte(j);
                CustomProgressBar.update((int)(i * 100 / inputStream.Length));
                while (bd < i && j < key.MaxBadBytes)
                {
                    bd = key.getBadByte(j);
                    j++;
                }

                if (bd == i)
                {
                    inputStream.ReadByte();
                    continue;
                }
                Console.WriteLine(-key.getCurByte((int)(ks % key.MaxCryptoLength)));
                outputStream.WriteByte((byte)ChangeByte(inputStream.ReadByte(), -key.getCurByte((int)(ks % key.MaxCryptoLength))));
                Console.WriteLine("Printed at " + i + " " + j + " " + bd + " " + ks);
                ks++;
            }

            inputStream.Close();
            outputStream.Close();
        }
Exemplo n.º 5
0
        public override void Encrypt(FileInfo input, FileInfo output)
        {
            if (Key == null)
            {
                throw new CryptException("Key File not founded!");
            }

            FileStream inputStream  = input.OpenRead();
            FileStream outputStream = output.OpenWrite();

            for (long i = 0; i < inputStream.Length; i++)
            {
                int Byte = inputStream.ReadByte();
                Byte = ChangeByte(Byte, 1);
                outputStream.WriteByte((byte)Byte);
                CustomProgressBar.update((int)((i + 1) * 100 / inputStream.Length));
            }

            inputStream.Close();
            outputStream.Close();
        }