Beispiel #1
0
        /// <summary>
        /// Шифрование текста.
        /// </summary>
        /// <param name="Text">Данные, требуемые шифровки.</param>
        /// <param name="Key">Ключ</param>
        /// <returns></returns>
        public static String Encrypt(String Text, Int32 Key)
        {
            String      Result = "", Letter = "";
            List <Char> Alphabet = Caesar.GetAlphabet(Text.GetAlphabet());

            for (int i = 0; i < Text.Length; i++)
            {
                if (Regex.IsMatch(Text[i].ToString(), "[А-Яа-я]|[A-Za-z]"))
                {
                    for (int j = 0; j < Alphabet.Count; j++)
                    {
                        if (Text[i].ToString().ToUpper() == Alphabet[j].ToString())
                        {
                            Letter = ((j + Key) >= Alphabet.Count)
                                ? Alphabet[(j + Key) - Alphabet.Count].ToString()
                                : Alphabet[j + Key].ToString();
                        }
                    }
                }
                else
                {
                    Letter = Text[i].ToString();
                }
                Result += Letter;
            }

            return(Result);
        }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        private Alphabet GenerationAlphabet()
        {
            Alphabet    Alphabet = (elem_RU.Checked) ? Alphabet.Cyrillic : Alphabet.Latin;
            List <Char> Chars    = Caesar.GetAlphabet(Alphabet);

            elem_alphabet.Text = Chars.Select(i => i.ToString()).Aggregate((result, item) => result + " " + item) + "\n";

            for (int i = (Chars.Count - (int)elem_key.Value); i < Chars.Count; i++)
            {
                elem_alphabet.Text += Chars[i].ToString() + " ";
            }

            for (int i = 0; i < (Chars.Count - (int)elem_key.Value); i++)
            {
                elem_alphabet.Text += Chars[i].ToString() + " ";
            }

            elem_alphabet.Text = elem_alphabet.Text.Remove(elem_alphabet.Text.Length - 1, 1);

            return(Alphabet);
        }
Beispiel #3
0
 /// <summary>
 /// Шифровка даннных
 /// </summary>
 private void elem_encrypt_Click(Object sender, EventArgs e)
 {
     GenerationAlphabet();
     elem_cipherText.Text = Caesar.Encrypt(elem_sourceText.Text, (int)elem_key.Value);
 }
Beispiel #4
0
 /// <summary>
 /// Дешифрование текста.
 /// </summary>
 /// <param name="Text">Данные, требуемые дешифровки.</param>
 /// <param name="Key">Ключ</param>
 /// <returns></returns>
 public static String Decrypt(String Text, Int32 Key)
 {
     return(Caesar.Encrypt(Text, -Key));
 }