protected override string GetEncryptedTextFromBinaries(List <string> input) { string returnDNAText = ""; foreach (string s in input) { if (s.Length != 8) { throw new Exception("DNA-GetEncryptedText: Binary Length Must Be 8"); } string tempKey; string tempValue; for (int i = 0; i < 8; i += 2) { tempKey = s.Substring(i, 2); if (DNACodeDictionary.TryGetValue(tempKey, out tempValue)) { returnDNAText += tempValue; } else { throw new Exception(string.Format("DNA-GetEncryptedText: Input {0} Is Not Valid", tempKey)); } } } return(returnDNAText); }
private int GetIntegerFromEnCodeWord(string word) { if (word.Length == 4) { string temp = ""; for (int i = 0; i < 4; i++) { temp += DNACodeDictionary.FirstOrDefault(x => x.Value.Equals(word[i].ToString())).Key; } int returnValue; // Make sure it is integer if (Int32.TryParse(temp, out returnValue)) { //Convert binary string to decimal return(Convert.ToInt32(temp, 2)); } else { throw new Exception(string.Format("GetIntegerFromEnCodeWord: Cannot Convert {0} To Integer", temp)); } } throw new Exception("GetIntegerFromEnCodeWord: Encode Word Length Must Be 4"); }