public string Encrypt(string message, Deck deck)
        {
            var key             = _shuffleAlgorithm.Shuffle(deck, message.Length);
            var cypherTextChars = message.Zip(
                key,
                (messageChar, keyCahrValue) =>
            {
                var messageCharValue = _shuffleAlgorithm.GetSymbolNumber(messageChar);
                var sum = messageCharValue + keyCahrValue;
                return(_shuffleAlgorithm.GetSymbolForNumber(sum));
            }).ToArray();

            return(new string(cypherTextChars));
        }
        internal static void AllNValuesCanChangePositions(this Assert _, IShuffle <ValuePriorityPair <int> > shuffle)
        {
            var elements = new ValuePriorityPairs <int>
            {
                new ValuePriorityPair <int>(1, 1),
                new ValuePriorityPair <int>(2, 2),
                new ValuePriorityPair <int>(3, 3),
                new ValuePriorityPair <int>(4, 4),
                new ValuePriorityPair <int>(5, 5),
            };

            var value1Set = new HashSet <int>();
            var value2Set = new HashSet <int>();
            var value3Set = new HashSet <int>();

            for (var i = 0; i < _iterations; i++)
            {
                var shuffled = shuffle.Shuffle(elements, 3).ToList();
                value1Set.Add(shuffled[0].Value);
                value2Set.Add(shuffled[1].Value);
                value3Set.Add(shuffled[2].Value);
            }

            Assert.AreEqual(elements.Count(), value1Set.Count);
            Assert.AreEqual(elements.Count(), value2Set.Count);
            Assert.AreEqual(elements.Count(), value3Set.Count);
        }
Ejemplo n.º 3
0
        private char[] ScrambleCharacterList()
        {
            var allCharacters = CleanCharacterList();

            shuffle.Shuffle(allCharacters);

            return(allCharacters);
        }
Ejemplo n.º 4
0
        public Tissue2D Create(int maxX, int maxY, float ratioHealthyCells, float ratioInfectedCells)
        {
            maxX = Math.Abs(maxX);
            maxY = Math.Abs(maxY);
            var totalCount = maxY * maxX;

            if (ratioHealthyCells + ratioInfectedCells > 1)
            {
                throw new InvalidOperationException("Cannot create more then 100% cells.");
            }

            int countHealthyCells  = (int)Math.Floor(ratioHealthyCells * totalCount);
            int countInfectedCells = (int)Math.Floor(ratioInfectedCells * totalCount);

            var xList = _shuffler.Shuffle(Enumerable.Range(0, maxX));
            var yList = _shuffler.Shuffle(Enumerable.Range(0, maxY));
            var cells = new List <ICell>();

            cells.AddRange(CreateHealthyCells(countHealthyCells));
            cells.AddRange(CreateInfectedCells(countInfectedCells));
            cells.AddRange(CreateEmptyPlaces(totalCount - countHealthyCells - countInfectedCells));
            var cellList = _shuffler.Shuffle(cells);

            for (int y = 0; y < maxY; y++)
            {
                for (int x = 0; x < maxX; x++)
                {
                    var currentCell = (y + 1) * (x + 1);
                    _tissue = _tissue.Add(
                        new Location(xList.ElementAt(x), yList.ElementAt(y)),
                        cellList.ElementAt(currentCell - 1));
                }
            }

            return(new Tissue2D(_tissue));
        }
Ejemplo n.º 5
0
        private List <Word> CreateWordsForGame(string wordList, int numberOfCards)
        {
            string wordListFile = (wordList.ToLower()) switch
            {
                "normal" => "normal1.txt",
                "adult" => "adult1.txt",
                "adult_uk" => "adult_uk1.txt",
                "adult_us" => "adult_us1.txt",
                _ => throw new ArgumentException("Unrecognized word list name used"),
            };

            var allWords = GetAllWordsInWordList(wordListFile);

            var wordCards = new List <Word>();

            var sides = new List <State> {
                State.Blank, State.Blue, State.Red
            };
            var numberOfCardsPerTeam = (numberOfCards - NumberOfAssassins) / sides.Count;

            foreach (var side in sides)
            {
                for (int index = 0; index < numberOfCardsPerTeam; index++)
                {
                    string word = PickNewUniqueWord(allWords, wordCards);
                    wordCards.Add(new Word {
                        Text = word, State = side
                    });
                }
            }

            for (int index = 0; index < NumberOfAssassins; index++)
            {
                string word = PickNewUniqueWord(allWords, wordCards);
                wordCards.Add(new Word {
                    Text = word, State = State.Assassin
                });
            }

            wordCards = _cardShuffler.Shuffle(wordCards).ToList();

            return(wordCards);
        }
Ejemplo n.º 6
0
        public void ScrambleFiles(IEnumerable <FileInfo> targets, DirectoryInfo destination)
        {
            FileInfo[] filesThatDontExist = targets.Where(e => !e.Exists).ToArray();
            if (filesThatDontExist.Any())
            {
                string fileNames = string.Join(Environment.NewLine, filesThatDontExist.Select(e => e.FullName));
                throw new FileNotFoundException(fileNames);
            }

            fileShuffler.Shuffle(targets.ToArray(), RandomProvider.Random);

            DirectoryInfo[] subDirectories = destination.GetDirectories();

            // no need to scramble if no subdirectories are found in destination
            if (!subDirectories.Any())
            {
                return;
            }

            directoryShuffler.Shuffle(subDirectories.ToArray(), RandomProvider.Random);
        }
Ejemplo n.º 7
0
        public static IEnumerable <T> Shuffle <T>(this IEnumerable <T> elements, IShuffle shuffleAlgorithm)
        {
            var shuffledSet = shuffleAlgorithm.Shuffle(elements);

            return(shuffledSet);
        }