public string Analyse(string plainText, string cipherText) // O() { SortedDictionary <char, char> KeyTable = new SortedDictionary <char, char>(); Dictionary <char, bool> alphaList = new Dictionary <char, bool>(); int PTLength = plainText.Length; int CTLength = cipherText.Length; plainText = plainText.ToLower(); cipherText = cipherText.ToLower(); for (int i = 0; i < PTLength; i++) // O(N) { if (!KeyTable.ContainsKey(plainText[i])) { KeyTable.Add(plainText[i], cipherText[i]); alphaList.Add(cipherText[i], true); } } if (KeyTable.Count != 26) //O(1) { Ceaser obj = new Ceaser(); string alphabet = obj.alphabet; for (int i = 0; i < 26; i++) { if (!KeyTable.ContainsKey(alphabet[i])) { for (int j = 0; j < 26; j++) { if (!alphaList.ContainsKey(alphabet[j])) { KeyTable.Add(alphabet[i], alphabet[j]); alphaList.Add(alphabet[j], true); j = 26; } } } } } string key = ""; foreach (var item in KeyTable) // O(1) { key += item.Value; } return(key); }
public Dictionary <char, char> KeyDictionary(string key, string Operation)// O(1) { Dictionary <char, char> dic = new Dictionary <char, char>(); Ceaser ceaser = new Ceaser(); for (int i = 0; i < 26; i++) { if (Operation == "encrypt") { dic.Add(ceaser.alphabet[i], key[i]); } else { dic.Add(key[i], ceaser.alphabet[i]); } } return(dic); }