Esempio n. 1
0
        public static IEnumerable <byte> GenerateKeyData(
            long lengthBytes, int seed, int gridWidth, int gridHeight, int generationsPerBlock)
        {
            CAGrid grid = new CAGrid();


            grid.BuildFromPseudoRandomNumbers(seed, gridWidth, gridHeight);


            long written   = 0;
            long remaining = lengthBytes;


            while (written < lengthBytes)
            {
                for (int i = 0; i < generationsPerBlock; i++)
                {
                    grid.RunFredkinRule();
                }


                byte[] buffer = grid.GetBytes();


                long toWrite = buffer.Length;


                if (remaining < buffer.Length)
                {
                    toWrite = remaining;
                }


                for (int i = 0; i < toWrite; i++)
                {
                    yield return(buffer[i]);
                }


                written += toWrite;


                remaining = lengthBytes - written;


                Debug.Print("Written:" + written + " bytes, remaining: " + remaining);


                OnProgress(lengthBytes, written, remaining);
            }
        }
Esempio n. 2
0
        public void GenerateCellData()
        {
            _caGrid = new CAGrid();
            _caGrid.BuildFromPassCode(_passCode, _passCodeSize);

            var s = Stopwatch.StartNew();

            while (_caGrid.Generation < _generationCount)
            {
                _caGrid.RunFredkinRule();
            }
            s.Stop();
            Debug.Print(s.ElapsedMilliseconds.ToString());
        }
Esempio n. 3
0
        public static void GenerateRandomFile(
            Stream outputStream, int lengthBytes, int seed, int gridWidth, int gridHeight, int generationsPerBlock)
        {
            CAGrid grid = new CAGrid();


            grid.BuildFromPseudoRandomNumbers(seed, gridWidth, gridHeight);

            int written   = 0;
            int remaining = lengthBytes;


            while (written < lengthBytes)
            {
                for (int i = 0; i < generationsPerBlock; i++)
                {
                    grid.RunFredkinRule();
                }


                byte[] buffer = grid.GetBytes();


                int toWrite = buffer.Length;


                if (remaining < buffer.Length)
                {
                    toWrite = remaining;
                }

                outputStream.Write(buffer, 0, toWrite);


                written += toWrite;


                remaining = lengthBytes - written;


                Debug.Print("Written:" + written + " bytes, remaining: " + remaining);
            }
        }