static void DebugConsoleCharGraphDrawing() { FrequencyAnalysis.DrawConsoleCharFrequencyGraph(EnglishLetterFrequency.GetLetterProportions(), 15); }
static Dictionary <char, char> GetMonoalphabeticMapping(string selectedTextOffsetSelection) { int graphHeight = 20; Dictionary <char, char> currentMapping = new Dictionary <char, char>(); foreach (char c in validCharacters) { currentMapping.Add(c, c); } bool editing = true; while (editing) { Console.WriteLine("\n\n"); string currentDeciphering = FrequencyAnalysis.DecipherTextByMapping(selectedTextOffsetSelection, currentMapping); Dictionary <char, double> englishCharacterProportions = EnglishLetterFrequency.GetLetterProportions(); Dictionary <char, double> selectionCharacterProportion = FrequencyAnalysis.CharFrequencyToCharProportion(FrequencyAnalysis.GetTextCharFrequency(currentDeciphering)); PrintSeperator(); Console.WriteLine("English Language Average Character Proportions (Target Proportions):"); FrequencyAnalysis.DrawConsoleCharFrequencyGraph(englishCharacterProportions, graphHeight, forcedContainChars: validCharacters); PrintSeperator(); Console.WriteLine(); PrintSeperator(); Console.WriteLine("Current Character Proportions:"); FrequencyAnalysis.DrawConsoleCharFrequencyGraph(selectionCharacterProportion, graphHeight, forcedContainChars: validCharacters); PrintSeperator(); Console.WriteLine("Request mapping swap ({character 1}:{character 2}) or leave blank to finish or +/- to increase/decrease graph magnification"); Console.Write("> "); string inputRequest = Console.ReadLine().ToUpper(); if (inputRequest.Length == 0) { editing = false; } else if (InputIsCharacterRemapping(inputRequest)) { char requestCharA = inputRequest[0]; char requestCharB = inputRequest[2]; Debug.Assert(inputRequest[1] == ':'); char currentInputCharToRequestCharA = ' '; char currentInputCharToRequestCharB = ' '; foreach (char c in currentMapping.Keys) { if (currentMapping[c] == requestCharA) { currentInputCharToRequestCharA = c; } if (currentMapping[c] == requestCharB) { currentInputCharToRequestCharB = c; } } if (currentInputCharToRequestCharA == ' ' || currentInputCharToRequestCharB == ' ') { Debug.Fail("Error: Failed to locate char mapping to request char"); } char requestInputCharOldMapping = currentMapping[currentInputCharToRequestCharA]; currentMapping[currentInputCharToRequestCharA] = requestCharB; currentMapping[currentInputCharToRequestCharB] = requestInputCharOldMapping; } else if (inputRequest == "+") { graphHeight += 5; } else if (inputRequest == "-") { if (graphHeight > 5) { graphHeight -= 5; } else { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Unable to further reduce graph height"); Console.ForegroundColor = ConsoleColor.White; } } else { Console.WriteLine("Unknown request"); } List <char> outputCharsUnique = new List <char>(); List <char> warnedCharsNonUnique = new List <char>(); foreach (char c in currentMapping.Keys) { char outputChar = currentMapping[c]; if (outputCharsUnique.Contains(outputChar) && !warnedCharsNonUnique.Contains(outputChar)) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"WARNING: duplicate mapping to character '{outputChar}'"); Console.ForegroundColor = ConsoleColor.White; warnedCharsNonUnique.Add(outputChar); } else { outputCharsUnique.Add(outputChar); } } } return(currentMapping); }