/// <summary> /// Add letter to the end of the text /// </summary> public void AddLetter(string letter, Alphabet alpha) { int position; if (this.caseSensitive == false) { if (char.IsUpper(letter.ToCharArray()[0]) == true) { this.orgCapital.Add(true); } else { this.orgCapital.Add(false); } 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); } }
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); }
public Text(string text, Alphabet alpha, int treatmentInvalidChars) { this.invalidCharProcess = treatmentInvalidChars; string curString = ""; string c = ""; string prep_text = text; if (this.caseSensitive == false) { 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; } } }