Ejemplo n.º 1
0
        private void Encrypt(TextBox txtDecrypted)
        {
            Char[]  message      = txtDecrypted.Text.ToCharArray();
            Int32   alphaIndex   = 0;
            Boolean isSpace      = false;
            Int32   alphaShifted = 0;
            Int32   shift        = 0;
            String  encrypted    = "";

            foreach (char c in message)
            {
                alphaIndex = (char.ToUpper(c) - 64);
                shift      = r.Sum;

                if (alphaIndex < 0)
                {
                    isSpace = true;
                }

                alphaShifted = (alphaIndex + shift) + 64;

                if (alphaShifted > 90)
                {
                    alphaShifted -= 26;
                }

                if (alphaShifted < 65)
                {
                    alphaShifted += 26;
                }

                if (isSpace)
                {
                    alphaShifted = 95;
                }

                encrypted += char.ToString((char)alphaShifted);
                r.IncrementRotors();
                isSpace = false;

                // Write output
                // Debug.WriteLine(alphaIndex.ToString() + " + " + shift.ToString() + " = " + (alphaShifted).ToString());
            }
            txtEncrypted.Text = encrypted.ToString();
        }