public void ReadDictFile(string file) { string[] lines = File.ReadAllLines(file); dict = new CipherDictionary(lines.Length); foreach (string line in lines) { if (line.Length == 10) { char c = line[0]; if (c == 'C') { c = '\r'; } else if (c == 'L') { c = '\n'; } else if (c == 'E') { c = (char)26; } string hex = line.Substring(4, 6); dict.Add(0xFF << 24 | Convert.ToInt32(hex, 16), c); } } if (data != null) { dict.AddMissingValues(data); } charsetView.DataSource = dict.BindingList; }
public void BestGuess() { CipherPair eof = null; if (data[data.Length - 1] == data[data.Length - 2] && data[data.Length - 1] == data[data.Length - 3]) { eof = new CipherPair(data[data.Length - 1], (char)26); } var codelist = data.Distinct(); var dicts = new List <CipherPredictionDictionary>(); dicts.Add(CipherPredictionDictionary.SingleFrequencyPrediction(data, eof)); int spaceCode = dicts[0].Find(p => p.MostLikely().Value == ' ').MostLikely().Code; dicts.Add(CipherPredictionDictionary.PairFrequencyPrediction(data, codelist, eof)); dicts.Add(CipherPredictionDictionary.FirstLetterPrediction(data, spaceCode)); dicts.Add(CipherPredictionDictionary.KnownWordPrediction(data, "<untranslatable>")); preDict = CipherPredictionDictionary.AggregateProbabilities(dicts, codelist); dict = preDict.MostLikely(); dict.AddMissingValues(codelist); charsetView.DataSource = dict.BindingList; }