public Message(string fileName) { _mode = ConstructorMode.FileName; YearlySettings ys = YearlySettings.Open(fileName); _settings = ys.Today; Wiring.Current = _settings.ParentSettings.Wiring; _machine = new Machine(_settings); MessageKey = RandomUtil.GetRandomAlpha(5); _fileName = fileName; }
public string Decipher(string value) { CipherText = value; string key; if (_mode == ConstructorMode.FileName || _mode == ConstructorMode.Id) { YearlySettings ys; if (_mode == ConstructorMode.Id) { ys = YearlySettings.ReadFromDb(_id); } else { ys = YearlySettings.Open(_fileName); } string indicator = CipherText.Split(CipherText.Where(c => char.IsWhiteSpace(c)).Distinct().ToArray(), StringSplitOptions.RemoveEmptyEntries)[0]; Settings s = ys[indicator]; Wiring.Current = s.ParentSettings.Wiring; } string result = FormatDecryptInput(value, out key); MessageKey = key; string expandedKey = string.Concat(key, _settings.StartPosition.Substring(5, 3)); _machine.Settings = _settings.StartPosition; string trueKey = _machine.Encipher(expandedKey); _machine.Settings = trueKey; result = _machine.Decipher(result); PlainText = FormatDecryptOutput(result).Trim(); return(PlainText); }