static void DebugGetFactoredKeyLengthWeightings() { Console.Write("Text> "); string text = Console.ReadLine().ToUpper(); Console.Write("Discard single occurences (1/0)?> "); bool discardSingle = int.Parse(Console.ReadLine()) != 0; Repetition[] repetitions = Repetition.GetTextRepetitions(text); Dictionary <int, int> keyLengthWeightings = KeyLengthDeduction.GetKeyLengthWeights(repetitions, discardSingle); Dictionary <int, int> factoredWeightings = KeyLengthDeduction.GetFactoredKeyLengthWeights(keyLengthWeightings); foreach (int factoredkeyLength in factoredWeightings.Keys) { Console.WriteLine($"{factoredkeyLength} : {factoredWeightings[factoredkeyLength]}"); } Console.WriteLine(); Console.Write("Get Top x Results> "); int count = int.Parse(Console.ReadLine()); Dictionary <int, int> topResults = ProgramMath.GetTopDictionaryKeysByValue(factoredWeightings, count); foreach (int topResult in topResults.Keys) { Console.WriteLine($"{topResult} : {topResults[topResult]}"); } }
static int KeyLengthSelection(string text) { Console.Write("Discard single-occurence key lengths (1/0)?> "); bool discardSingle = int.Parse(Console.ReadLine()) != 0; Repetition[] repetitions = Repetition.GetTextRepetitions(text); Dictionary <int, int> keyLengthWeightings = KeyLengthDeduction.GetKeyLengthWeights(repetitions, discardSingle); Dictionary <int, int> factoredWeightings = KeyLengthDeduction.GetFactoredKeyLengthWeights(keyLengthWeightings); Console.Write("View how many top lengths?> "); int topLengthsCount = int.Parse(Console.ReadLine()); int requestCount = topLengthsCount < factoredWeightings.Count ? topLengthsCount : factoredWeightings.Count; Dictionary <int, int> topLengths = ProgramMath.GetTopDictionaryKeysByValue(factoredWeightings, requestCount); Console.WriteLine(); Console.WriteLine("(English average IOC is about 0.0667)"); Console.WriteLine("Top Key Lengths:"); foreach (int length in topLengths.Keys) { decimal ioc = KeyLengthDeduction.GetAverageIOCOfTextByOffset(text, length); Console.WriteLine($"{length} (weighting = {topLengths[length]}) - Average IOC = {ioc}"); } Console.Write("Select chosen key length> "); int keyLengthSelection = int.Parse(Console.ReadLine()); return(keyLengthSelection); }
static void DebugStringByOffset() { Console.WriteLine("Text:"); string text = Console.ReadLine(); Console.Write("Offset> "); int offset = int.Parse(Console.ReadLine()); string[] texts = KeyLengthDeduction.GetTextsFromStringByOffset(text, offset); foreach (string sampleText in texts) { Console.WriteLine(sampleText); } }
static void DebugGetKeyLengthWeightings() { Console.Write("Text> "); string text = Console.ReadLine().ToUpper(); Console.Write("Discard single occurences (1/0)?> "); bool discardSingle = int.Parse(Console.ReadLine()) != 0; Repetition[] repetitions = Repetition.GetTextRepetitions(text); Dictionary <int, int> keyLengthWeightings = KeyLengthDeduction.GetKeyLengthWeights(repetitions, discardSingle); foreach (int keyLength in keyLengthWeightings.Keys) { Console.WriteLine($"{keyLength} : {keyLengthWeightings[keyLength]}"); } }
static void DebugOptimalCharacterMappingFull() { Console.Write("Text> "); string text = Console.ReadLine().ToUpper(); const bool discardSingle = true; Repetition[] repetitions = Repetition.GetTextRepetitions(text); Dictionary <int, int> keyLengthWeightings = KeyLengthDeduction.GetKeyLengthWeights(repetitions, discardSingle); Dictionary <int, int> factoredWeightings = KeyLengthDeduction.GetFactoredKeyLengthWeights(keyLengthWeightings); const int topLengthsCount = 7; Dictionary <int, int> topLengths = ProgramMath.GetTopDictionaryKeysByValue(factoredWeightings, topLengthsCount); Console.WriteLine(); Console.WriteLine("Top Key Lengths:"); foreach (int length in topLengths.Keys) { Console.WriteLine($"{length} (weighting = {topLengths[length]})"); } Console.Write("Select chosen key length> "); int keyLengthSelection = int.Parse(Console.ReadLine()); string[] selections = FrequencyAnalysis.SplitTextByOffset(text, keyLengthSelection); Console.WriteLine(); Console.WriteLine("Text Offset Selections:"); for (int i = 0; i < selections.Length; i++) { Console.WriteLine(i + ") " + selections[i]); } Console.Write("Select text offset selection> "); int offsetSelectionIndex = int.Parse(Console.ReadLine()); Debug.Assert(0 <= offsetSelectionIndex && offsetSelectionIndex < selections.Length); string selectedTextOffsetSelection = selections[offsetSelectionIndex]; Dictionary <char, double> selectionCharacterProportion = FrequencyAnalysis.CharFrequencyToCharProportion(FrequencyAnalysis.GetTextCharFrequency(selectedTextOffsetSelection)); Dictionary <char, double> englishCharacterProportions = EnglishLetterFrequency.GetLetterProportions(); double mappingDifference; int _; Dictionary <char, char> optimalMapping = FrequencyAnalysis.GetOptimalCharacterMapping(selectionCharacterProportion, englishCharacterProportions, out mappingDifference, out _); Console.WriteLine(); Console.WriteLine($"Mapping Difference: {mappingDifference}"); foreach (char textChar in optimalMapping.Keys) { Console.WriteLine($"{textChar} -> {optimalMapping[textChar]}"); } }