Ejemplo n.º 1
0
        public static void Main(string[] args)
        {
            BasylKeyGenerator bkg = new BasylKeyGenerator("Hi", 1024, 900, 1240, 1024, "ABCD", new byte[(32)], new byte[(4)], new byte[(4)], false, new StrongerBasylPseudoAdaptor());

            FileStream s    = File.OpenWrite("Heh.dat");
            int        size = 1024 * 1024 * 25;

            byte[] m = new byte[size];
            while (true)
            {
                bkg.FillBytes(m);
                s.Write(m, 0, size);

                for (int i = 0; i < size - 1; i++)
                {
                    m[i] += m[i + 1];
                }

                for (int i = size - 2; i >= 0; i--)
                {
                    m[i] += m[i + 1];
                }
                s.Write(m, 0, size);
            }


            Console.ReadLine();
        }
Ejemplo n.º 2
0
        public static void Main(string[] args)
        {
            BasylKeyGenerator bkg = new BasylKeyGenerator("Hi", 1024, 900, 1240, 1024, "ABCD", new byte[(32)], new byte[(4)], new byte[(4)], false, new StrongerBasylPseudoAdaptor());

            FileStream s = File.OpenWrite("Heh.dat");
            int size = 1024*1024*25;
            byte[] m = new byte[size];
            while (true)
            {
                bkg.FillBytes(m);
                s.Write(m, 0, size);

                for(int i = 0; i < size -1; i++)
                {
                    m[i] += m[i + 1];
                }

                for (int i = size - 2; i >= 0; i--)
                {
                    m[i] += m[i + 1];
                }
                s.Write(m, 0, size);

            }

            Console.ReadLine();
        }
Ejemplo n.º 3
0
        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();
        }
Ejemplo n.º 4
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();
        }
Ejemplo n.º 5
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();
        }
        private string GenerateRandomFunction(string keyPhrase)
        {
            BasylKeyGenerator generator = new BasylKeyGenerator(keyPhrase, BasylKeyGenerator.INITIAL / 4, BasylKeyGenerator.ROUNDS, BasylKeyGenerator.LEFTOFF, BasylKeyGenerator.EXPANSION / 20, BasylKeyGenerator.ADDITIONALKEY, new byte[32], new byte[4], new byte[4], true, new StrongerBasylPseudoAdaptor());

            List<String> variables = new List<string>();
            List<String> operators = new List<string>();

            variables.Add("seed");
            variables.Add("pos");

            operators.AddRange("+,*,%,^,|,&,+,*,*,+".Split(','));

            bool operMode = false;
            String res = "pos * seed + pos + ";
            while ((generator.GetRandomByte() % 29) != (generator.GetRandomByte() % 29) || !operMode)
            {

                if (operMode)
                {

                    res += operators[generator.GetRandomByte() % operators.Count] + " ";

                    operMode = false;
                }
                else
                {
                    if (generator.GetRandomByte() % 8 == 0)
                    {
                        //literal
                        res += (Math.Abs(BitConverter.ToInt32(new byte[] { generator.GetRandomByte(), generator.GetRandomByte(), generator.GetRandomByte(), generator.GetRandomByte() }, 0)) % 256 * 256 * 12 + " ");
                    }
                    else
                    {
                        //variable
                        res += variables[generator.GetRandomByte() % variables.Count] + " ";
                    }

                    operMode = true;
                }

            }
            return res;
        }
        /// <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();
        }