Exemple #1
0
        private void SavePattern_Action()
        {
            if (!ValidatePattern())
            {
                return;
            }
            var lines = new List <string>(new[] { RowPattern }); // initialize with the first line.

            for (var offset = 1; offset < RowPattern.Length; offset++)
            {
                var chunk      = RowPattern.Substring(0, RowPattern.Length - offset);
                var otherpart  = RowPattern.Remove(0, RowPattern.Length - offset);
                var newpattern = otherpart + chunk;
                lines.Add(newpattern);
            }
            VigenereMatrix = lines.ToArray(); // SampleMatrix.AllText.Split(new[] { '\n', '\r' }, System.StringSplitOptions.RemoveEmptyEntries);  // for testing
            TriggerTranslate();
        }
Exemple #2
0
        private bool ValidatePattern()
        {
            // validate that the RowPattern input passes this requirements for the Vigenere Square
            // 1. not blank.
            if (string.IsNullOrWhiteSpace(RowPattern))
            {
                MessageBox.Show("Please enter a sequence in the input box.");

                RowPattern = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
                return(false);
            }
            // 2. must be 26 letters, no duplicates, no whacky characters.
            if (RowPattern.Length != 26 || !RowPattern.All(ltr => "ABCDEFGHIJKLMNOPQRSTUVWXYZ".Contains(ltr.ToString().ToUpper())))
            {
                MessageBox.Show("The sequence must be 26 letters, 1 instance or each letter, no duplicates, and no special characters or numbers.");
                return(false);
            }
            return(true);
        }