static void DebugGetPermutations() { Console.Write("Values> "); string[] values = Console.ReadLine().Split(','); foreach (List <string> perm in ProgramMath.GetPermutations(new List <string>(values))) { foreach (string part in perm) { Console.Write(part); } Console.WriteLine(); } }
public static Dictionary <char, char> GetOptimalCharacterMappingNonCaesar(Dictionary <char, double> textCharProportion, Dictionary <char, double> targetCharProportion, out double mappingDifference) { /*Mappings are { inputTextChar : actualChar }*/ double minDifference = double.MaxValue; Dictionary <char, char> optimalMapping = null; foreach (List <char> charList in ProgramMath.GetPermutations(new List <char>(Program.validCharacters))) { /*Create Character Mapping*/ Dictionary <char, char> mapping = new Dictionary <char, char>(); for (int i = 0; i < Program.validCharacters.Length; i++) { mapping[charList[i]] = Program.validCharacters[i]; } /*Test character mapping*/ Dictionary <char, double> mappedCharProportions = new Dictionary <char, double>(); foreach (char key in textCharProportion.Keys) { mappedCharProportions[mapping[key]] = textCharProportion[key]; } double difference = ProgramMath.GetKeyFrequencyDifference(mappedCharProportions, targetCharProportion); /*Compare mapping to best*/ if (difference < minDifference) { minDifference = difference; optimalMapping = new Dictionary <char, char>(mapping); } } mappingDifference = minDifference; return(optimalMapping); }