public FileMutatedBKG(BasylKeyGenerator keyGen, Stream stream)
        {
            this.generator = keyGen;
            this.cipher = new BESCipher(keyGen);

            byte[] extra = new byte[100];
            byte[] extra2 = new byte[64];

            int amount = 65536;
            while (amount != 0)
            {
                byte[] buffer = new byte[amount];
                while (stream.Position + amount < stream.Length)
                {
                    stream.Read(buffer, 0, amount);
                    cipher.EncryptRight(ref buffer);
                    cipher.EncryptLeft(ref extra);
                    cipher.EncryptRight(ref extra2);
                }
                cipher.EncryptLeft(ref extra2);
                cipher.Shuffle(2);
                amount /= 2;
            }

            prg = new PseudoRandomGenerator(256 * 256, "MutatedBKG", 500);
            prg.ExpandKey(1);
            prg.SetSeedKey(extra);
            prg.SetSHA(extra2);
            prg.Recycle();

            stream.Close();
        }
        public static byte[] BasylHashUno(Stream stream, string pass, int hashSize, int keySize, int rounds, int skipOver, string additionalPass)
        {
            PseudoRandomGenerator prng = new PseudoRandomGenerator(keySize, pass, rounds);

            prng.SetRecycleKey(additionalPass);

            BESCipher cipher = new BESCipher(new BasylWeakKeyGenerator(prng));

            prng.Recycle();

            byte[] buff = new byte[65536];
            while (stream.Position + 65536 < stream.Length)
            {
                stream.Read(buff, 0, 65536);
                cipher.EncryptLeft(ref buff);
            }

            int x = stream.ReadByte();

            while (x != -1)
            {
                byte z = (byte)x;
                cipher.EncryptLeft(ref z);
                x = stream.ReadByte();
            }


            for (int i = 0; i < skipOver; i++)
            {
                prng.GetRandomInt();
            }

            int max = prng.GetRandomByte() * prng.GetRandomByte() + prng.GetRandomByte();

            for (int i = 0; i < max; i++)
            {
                prng.GetRandomInt();
            }

            byte[] BHU = new byte[hashSize];
            prng.FillBytes(BHU);

            for (int i = 0; i < hashSize; i++)
            {
                BHU[i] ^= prng.GetRandomByte();
                cipher.EncryptRight(ref BHU);
            }

            return(BHU);
        }
        public static byte[] BasylHashUno(String str, string pass, int hashSize, int keySize, int rounds, int skipOver, string additionalPass)
        {
            PseudoRandomGenerator prng = new PseudoRandomGenerator(keySize, pass, rounds);

            prng.SetRecycleKey(additionalPass);

            IBasylKeyGenerator wk     = new BasylWeakKeyGenerator(prng);
            BESCipher          cipher = new BESCipher(wk);

            prng.Recycle();

            foreach (char n in str)
            {
                byte q = (byte)n;
                cipher.EncryptLeft(ref q);
            }


            for (int i = 0; i < skipOver; i++)
            {
                for (int x = 0; x < 4; x++)
                {
                    prng.GetRandomByte();
                }
            }

            int max = prng.GetRandomByte() * prng.GetRandomByte() + prng.GetRandomByte();

            for (int i = 0; i < max; i++)
            {
                for (int x = 0; x < 4; x++)
                {
                    prng.GetRandomByte();
                }
            }

            byte[] BHU = new byte[hashSize];
            wk.FillBytes(BHU, 0, BHU.Length);

            for (int i = 0; i < hashSize; i++)
            {
                BHU[i] ^= prng.GetRandomByte();
                cipher.EncryptRight(ref BHU);
            }

            return(BHU);
        }
        public static byte[] BasylHashUno(Stream stream, string pass, int hashSize, int keySize, int rounds, int skipOver, string additionalPass)
        {
            PseudoRandomGenerator prng = new PseudoRandomGenerator(keySize, pass, rounds);
            prng.SetRecycleKey(additionalPass);

            BESCipher cipher = new BESCipher(new BasylWeakKeyGenerator(prng));
            prng.Recycle();

            byte[] buff = new byte[65536];
            while(stream.Position + 65536 < stream.Length)
            {
                stream.Read(buff, 0, 65536);
                cipher.EncryptLeft(ref buff);
            }

            int x = stream.ReadByte();
            while(x != -1)
            {
                byte z = (byte)x;
                cipher.EncryptLeft(ref z);
                x = stream.ReadByte();
            }

            for(int i = 0; i < skipOver; i++)
            {
                prng.GetRandomInt();
            }

            int max  =  prng.GetRandomByte() * prng.GetRandomByte() + prng.GetRandomByte();
            for (int i = 0; i < max; i++)
            {
                prng.GetRandomInt();
            }

            byte[] BHU = new byte[hashSize];
            prng.FillBytes(BHU);

            for (int i = 0; i < hashSize; i++)
            {
                BHU[i] ^= prng.GetRandomByte();
                cipher.EncryptRight(ref BHU);
            }

            return BHU;
        }
Example #5
0
        /// <summary>
        /// Decrypts a file with the parameters.
        /// </summary>
        /// <param name="input"></param>
        /// <param name="output"></param>
        /// <param name="pass"></param>
        /// <param name="initial"></param>
        /// <param name="rounds"></param>
        /// <param name="leftoff"></param>
        /// <param name="expansion"></param>
        /// <param name="additionalKey"></param>
        /// <param name="callback"></param>
        public static void Decrypt(Stream input, Stream output, string pass, int initial, int rounds, int leftoff, int expansion, string additionalKey, BasylFileEncryption.Callback callback, BasylPseudoAdaptor adaptor)
        {
            //read in the necessary randomized info.

            byte[] sha = new byte[32];
            byte[] f   = new byte[4];
            byte[] f2  = new byte[4];

            input.Read(sha, 0, 32);
            input.Read(f2, 0, 4);
            input.Read(f, 0, 4);

            BasylKeyGenerator bkg    = new BasylKeyGenerator(pass, initial, rounds, leftoff, expansion, additionalKey, sha, f, f2, true, adaptor);
            BESCipher         cipher = new BESCipher(bkg);

            int speed = MAX_SPEED;

            while (speed > MIN_SPEED)
            {
                //Encrypt Entire File in Chunks
                byte[] buffer = new byte[speed];
                while (input.Position + speed <= input.Length)
                {
                    input.Read(buffer, 0, speed);

                    cipher.EncryptLeft(ref buffer);
                    output.Write(buffer, 0, speed);

                    if (callback != null)
                    {
                        callback((double)input.Position / input.Length);
                    }
                }
                speed >>= 1;
            }

            input.Close();
            output.Close();
        }
Example #6
0
        /// <summary>
        /// Encrypts a file from the parameters.
        /// </summary>
        /// <param name="input"></param>
        /// <param name="output"></param>
        /// <param name="pass"></param>
        /// <param name="initial"></param>
        /// <param name="rounds"></param>
        /// <param name="leftoff"></param>
        /// <param name="expansion"></param>
        /// <param name="additionalKey"></param>
        /// <param name="callback"></param>
        /// <param name="adaptor"></param>
        public static void Encrypt(Stream input, Stream output, string pass, int initial, int rounds, int leftoff, int expansion, string additionalKey, BasylFileEncryption.Callback callback, BasylPseudoAdaptor adaptor)
        {
            //The SHA guarantees that no two files will have the same key for encryption and decryption.
            byte[] sha = SHA256.Create().ComputeHash(input);
            input.Position = 0;
            BasylKeyGenerator bkg = new BasylKeyGenerator(pass, initial, rounds, leftoff, expansion, additionalKey, sha, adaptor);

            //write out the necessary randomized info.
            output.Write(sha, 0, 32);
            output.Write(bkg.GetSecondRandomizer(), 0, 4);
            output.Write(bkg.GetEncryptedKey1Random(), 0, 4);


            BESCipher cipher = new BESCipher(bkg);

            int speed = MAX_SPEED;

            while (speed > MIN_SPEED)
            {
                //Encrypt Entire File in Chunks
                byte[] buffer = new byte[speed];
                while (input.Position + speed <= input.Length)
                {
                    input.Read(buffer, 0, speed);

                    cipher.EncryptRight(ref buffer);
                    output.Write(buffer, 0, speed);

                    if (callback != null)
                    {
                        callback((double)input.Position / input.Length);
                    }
                }
                speed >>= 1;
            }

            input.Close();
            output.Close();
        }
        public static byte[] BasylHashUno(String str, string pass, int hashSize, int keySize, int rounds, int skipOver, string additionalPass)
        {
            PseudoRandomGenerator prng = new PseudoRandomGenerator(keySize, pass, rounds);
            prng.SetRecycleKey(additionalPass);

            IBasylKeyGenerator wk = new BasylWeakKeyGenerator(prng);
            BESCipher cipher = new BESCipher(wk);
            prng.Recycle();

            foreach(char n in str)
            {
                byte q = (byte)n;
                cipher.EncryptLeft(ref q);
            }

            for (int i = 0; i < skipOver; i++)
            {
                for (int x = 0; x < 4; x++ )
                    prng.GetRandomByte();
            }

            int max = prng.GetRandomByte() * prng.GetRandomByte() + prng.GetRandomByte();
            for (int i = 0; i < max; i++)
            {
                for (int x = 0; x < 4; x++)
                    prng.GetRandomByte();
            }

            byte[] BHU = new byte[hashSize];
            wk.FillBytes(BHU, 0, BHU.Length);

            for (int i = 0; i < hashSize; i++)
            {
                BHU[i] ^= prng.GetRandomByte();
                cipher.EncryptRight(ref BHU);
            }

            return BHU;
        }
        /// <summary>
        /// Encrypts a file from the parameters.
        /// </summary>
        /// <param name="input"></param>
        /// <param name="output"></param>
        /// <param name="pass"></param>
        /// <param name="initial"></param>
        /// <param name="rounds"></param>
        /// <param name="leftoff"></param>
        /// <param name="expansion"></param>
        /// <param name="additionalKey"></param>
        /// <param name="callback"></param>
        /// <param name="adaptor"></param>
        public static void Encrypt(Stream input, Stream output, string pass, int initial, int rounds, int leftoff, int expansion, string additionalKey, BasylFileEncryption.Callback callback, BasylPseudoAdaptor adaptor)
        {
            //The SHA guarantees that no two files will have the same key for encryption and decryption.
            byte[] sha = SHA256.Create().ComputeHash(input);
            input.Position = 0;
            BasylKeyGenerator bkg = new BasylKeyGenerator(pass, initial, rounds, leftoff, expansion, additionalKey, sha, adaptor);

            //write out the necessary randomized info.
            output.Write(sha, 0, 32);
            output.Write(bkg.GetSecondRandomizer(), 0, 4);
            output.Write(bkg.GetEncryptedKey1Random(), 0, 4);

            BESCipher cipher = new BESCipher(bkg);

            int speed = MAX_SPEED;
            while (speed > MIN_SPEED)
            {
                //Encrypt Entire File in Chunks
                byte[] buffer = new byte[speed];
                while (input.Position + speed <= input.Length)
                {
                    input.Read(buffer, 0, speed);

                    cipher.EncryptRight(ref buffer);
                    output.Write(buffer, 0, speed);

                    if (callback != null)
                    {
                        callback((double)input.Position / input.Length);
                    }

                }
                speed >>= 1;
            }

            input.Close();
            output.Close();
        }
        /// <summary>
        /// Decrypts a file with the parameters.
        /// </summary>
        /// <param name="input"></param>
        /// <param name="output"></param>
        /// <param name="pass"></param>
        /// <param name="initial"></param>
        /// <param name="rounds"></param>
        /// <param name="leftoff"></param>
        /// <param name="expansion"></param>
        /// <param name="additionalKey"></param>
        /// <param name="callback"></param>
        public static void Decrypt(Stream input, Stream output, string pass, int initial, int rounds, int leftoff, int expansion, string additionalKey, BasylFileEncryption.Callback callback, BasylPseudoAdaptor adaptor)
        {
            //read in the necessary randomized info.

            byte[] sha = new byte[32];
            byte[] f = new byte[4];
            byte[] f2 = new byte[4];

            input.Read(sha, 0, 32);
            input.Read(f2, 0, 4);
            input.Read(f, 0, 4);

            BasylKeyGenerator bkg = new BasylKeyGenerator(pass, initial, rounds, leftoff, expansion, additionalKey, sha, f, f2, true, adaptor);
            BESCipher cipher = new BESCipher(bkg);

            int speed = MAX_SPEED;
            while (speed > MIN_SPEED)
            {
                //Encrypt Entire File in Chunks
                byte[] buffer = new byte[speed];
                while (input.Position + speed <= input.Length)
                {
                    input.Read(buffer, 0, speed);

                    cipher.EncryptLeft(ref buffer);
                    output.Write(buffer, 0, speed);

                    if (callback != null)
                    {
                        callback((double)input.Position / input.Length);
                    }

                }
                speed >>= 1;
            }

            input.Close();
            output.Close();
        }