Example #1
0
        public override string ToString()
        {
            StringBuilder res = new StringBuilder(cipherText.Length * 2 + 200 + key.size * key.size * 4);
            int           i;

            res.Append("Shift: " + shift + "$$");

            res.Append("Key Matrix: $");
            for (i = 0; i < key.size * key.size; i++)
            {
                if (i % key.size == 0)
                {
                    res.Append("$");
                }
                res.Append((char)(key.matrix[i] + 'A') + " ");
            }

            res.Append("$$A: " + a + " |B: " + b + "$$");

            res.Append("Char Substitutions:$");
            for (int c = 'A'; c <= 'Z'; c++)
            {
                res.Append((char)c);
            }

            res.Append("$");

            foreach (string s in assign)
            {
                res.Append(s);
            }

            res.Append("$$");

            res.Append("Texts:$");
            for (i = 0; i + 40 < cipherText.Length; i += 40)
            {
                res.Append(cipherText.Substring(i, 40) + "$");
                res.Append(Plaintext.Substring(i, 40) + "$");
                res.Append("$");
            }
            res.Append(cipherText.Substring(i) + "$");
            res.Append(Plaintext.Substring(i) + "$");

            return(res.ToString());
        }
Example #2
0
        public IEnumerable <Token> Tokenize(Plaintext input)
        {
            List <Match> matches  = input.FirstMatches(this.Patterns).ToList();
            Location     location = input.Beginning;

            while (matches.Any() && location is InnerLocation inner)
            {
                Token output = TokenAt(location, input, matches);
                if (!(output is Ignored))
                {
                    yield return(output);
                }
                matches  = this.Advance(matches, output.LocationAfter).ToList();
                location = output.LocationAfter;
            }

            if (location is InnerLocation remaining)
            {
                yield return(new InvalidInput(remaining, EndOfText.Value, input.Substring(remaining)));
            }

            yield return(new EndOfInput(location));
        }