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 CipherDictionary MostLikely() { var ret = new CipherDictionary(this.Count); foreach (CipherPossibilities poss in this) { CipherPair ml = poss.MostLikely(); if (ml != null) { ret.Add(ml); } } return(ret); }
public static string Substitute(int[] data, CipherDictionary dict) { StringBuilder sb = new StringBuilder(data.Length); for (int i = 0; i < data.Length; i++) { char c; if (!dict.TryGetValue(data[i], out c)) { c = UNKNOWN_CHAR; } sb.Append(c); } return(sb.ToString()); }
public void SaveDictFile(CipherDictionary dict, string path) { try { StreamWriter writer = File.CreateText(path); foreach (CipherPair pair in dict) { writer.WriteLine("{1} = {0:X6}", 0x00FFFFFF & pair.Code, GetPrintableForm(pair.Value)); } writer.Close(); } catch (IOException e) { throw new ArgumentException("IO error saving file", "path", e); } }
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; }