Esempio n. 1
0
        /// <summary>
        /// Run a letter through the scrambler in reverse.
        /// </summary>
        /// <param name="letter"></param>
        /// <returns></returns>
        public char ReverseScramble(char letter)
        {
            if (letter == ' ')
            {
                return(letter);
            }

            var code = EnigmaHelper.ToCode(letter);

            return(EnigmaHelper.ToLetter(wirings.ToList().IndexOf(code)));
        }
Esempio n. 2
0
        /// <summary>
        /// Run a letter through the scrambler.
        /// </summary>
        /// <param name="letter"></param>
        /// <returns></returns>
        public char Scramble(char letter)
        {
            if (letter == ' ')
            {
                return(letter);
            }

            var index           = EnigmaHelper.ToCode(letter);
            var scrambledLetter = EnigmaHelper.ToLetter(wirings[index]);

            return(scrambledLetter);
        }
Esempio n. 3
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);
        }
Esempio n. 4
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]));
            }
        }