Exemplo n.º 1
0
        public char Reflect(char letter)
        {
            if (letter == ' ')
            {
                return(letter);
            }

            char swappedLetter;
            var  code    = EnigmaHelper.ToCode(letter);
            var  codePos = Array.IndexOf(letterSwaps1, code);

            if (codePos < 0)
            {
                codePos       = Array.IndexOf(letterSwaps2, code);
                swappedLetter = EnigmaHelper.ToLetter(letterSwaps1[codePos]);
            }
            else
            {
                swappedLetter = EnigmaHelper.ToLetter(letterSwaps2[codePos]);
            }

            return(swappedLetter);
        }
Exemplo n.º 2
0
        public char Process(char letter)
        {
            if (letter == ' ')
            {
                return(letter);
            }

            var code  = EnigmaHelper.ToCode(letter);
            var cable = this.cables.SingleOrDefault(c => c.Contains(code));

            if (cable == null)
            {
                return(letter);
            }

            if (Array.IndexOf(cable, code) == 0)
            {
                return(EnigmaHelper.ToLetter(cable[1]));
            }
            else
            {
                return(EnigmaHelper.ToLetter(cable[0]));
            }
        }