Example #1
0
        /// <summary>
        /// Add letter to the end of the text
        /// </summary>
        public void AddLetter(string letter, Alphabet alpha)
        {
            int position;

            if (this.caseSensitive == false)
            {
                this.orgCapital.Add(char.IsUpper(letter.ToCharArray()[0]));
                position = alpha.GetPositionOfLetter(letter.ToLower());
            }
            else
            {
                position = alpha.GetPositionOfLetter(letter);
                this.orgCapital.Add(false);
            }

            if (position >= 0)
            {
                this.text.Add(position);
            }
            else
            {
                this.notInAlphabet.Add(letter);
                this.text.Add(-this.notInAlphabet.Count);
            }
        }
Example #2
0
        public List <Byte[]> ToSingleWords(Alphabet alpha)
        {
            int space = alpha.GetPositionOfLetter(" ");

            List <Byte[]> result = new List <Byte[]>();

            List <Byte> word = new List <Byte>();

            for (int i = 0; i < this.text.Count; i++)
            {
                if (this.text[i] != space)
                {
                    word.Add((byte)this.text[i]);
                }
                else
                {
                    if (word != null && word.Count != 0)
                    {
                        result.Add(word.ToArray());
                        word = new List <Byte>();
                    }
                }
            }
            if (word != null && word.Count != 0)
            {
                result.Add(word.ToArray());
                word = new List <Byte>();
            }

            return(result);
        }
Example #3
0
        private int[] KeyCreatedByMatch(int[] key, Alphabet cipher_alpha, string ct_word, Alphabet plain_alpha, string dic_word)
        {
            int[] newkey = new int[key.Length];
            for (int i = 0; i < newkey.Length; i++)
            {
                newkey[i] = key[i];
            }
            int ct_index;
            int pt_index;

            for (int i = 0; i < ct_word.Length; i++)
            {
                ct_index = cipher_alpha.GetPositionOfLetter(ct_word.Substring(i, 1));
                pt_index = plain_alpha.GetPositionOfLetter(dic_word.Substring(i, 1));
                if ((!newkey.Contains(pt_index)) && (newkey[ct_index] == -1))
                {
                    newkey[ct_index] = pt_index;
                }

                if ((newkey[ct_index] != pt_index) && (newkey[ct_index] != -1))
                {
                    return(null);
                }
            }

            return(newkey);
        }
Example #4
0
        public Text(string text, Alphabet alpha, int treatmentInvalidChars, bool caseSensitive = false)
        {
            this.invalidCharProcess = treatmentInvalidChars;
            this.caseSensitive      = caseSensitive;

            string curString = "";
            string c         = "";

            string prep_text = text;

            if (!this.caseSensitive)
            {
                for (int i = 0; i < prep_text.Length; i++)
                {
                    bool status = false;

                    int j = 0;
                    do
                    {
                        j++;
                        curString = prep_text.Substring(i, j);

                        c = curString;
                        if (char.IsUpper(c.ToCharArray()[0]))
                        {
                            status = true;
                            c      = c.ToLower();
                        }
                    }while (alpha.GetNumberOfLettersStartingWith(c) > 1);

                    if (alpha.GetNumberOfLettersStartingWith(c) == 1)
                    {
                        this.text.Add(alpha.GetPositionOfLetter(c));
                        this.orgCapital.Add(status);
                    }
                    else if (alpha.GetNumberOfLettersStartingWith(c) == 0)
                    {
                        this.notInAlphabet.Add(curString);
                        this.text.Add(-this.notInAlphabet.Count);
                        this.orgCapital.Add(false);
                    }
                    i += j - 1;
                }
            }
            else
            {
                for (int i = 0; i < prep_text.Length; i++)
                {
                    int j = 0;
                    do
                    {
                        j++;
                        curString = prep_text.Substring(i, j);
                        c         = curString;
                    }while (alpha.GetNumberOfLettersStartingWith(c) > 1);

                    if (alpha.GetNumberOfLettersStartingWith(c) == 1)
                    {
                        this.text.Add(alpha.GetPositionOfLetter(c));
                        this.orgCapital.Add(false);
                    }
                    else if (alpha.GetNumberOfLettersStartingWith(c) == 0)
                    {
                        this.notInAlphabet.Add(curString);
                        this.text.Add(-this.notInAlphabet.Count);
                        this.orgCapital.Add(false);
                    }
                    i += j - 1;
                }
            }
        }