public static WordDictionary LoadDictionary(Config conf) { var loader = new ExplicitXmlDictionaryLoader(); WordDictionary result; if (conf.UseCustomDictionary && !String.IsNullOrEmpty(conf.PathOfCustomDictionary) && System.IO.File.Exists(conf.PathOfCustomDictionary)) { result = loader.LoadFrom(conf.PathOfCustomDictionary); } else { using (var s = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(DictionaryResourceName)) { result = loader.LoadFrom(s); } } return(result); }
static void Main(string[] args) { Console.OutputEncoding = Encoding.UTF8; var sw = System.Diagnostics.Stopwatch.StartNew(); var generator = new ReadablePassphraseGenerator(GetRandomness()); var loader = new ExplicitXmlDictionaryLoader(); var dict = loader.LoadFrom(new DirectoryInfo(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location))); generator.SetDictionary(dict); sw.Stop(); Console.WriteLine("Loaded dictionary of type '{0}' with {1:N0} words in {2:N2}ms ({3:N3} words / sec)", loader.GetType().Name, generator.Dictionary.Count, sw.Elapsed.TotalMilliseconds, generator.Dictionary.Count / sw.Elapsed.TotalSeconds); // Basic statistics / samples. //GenerateSamples(PhraseStrength.Random, generator); //DictionaryCheck(generator); //CombinationCount(generator); // Short benchmarks. //BenchmarkGeneration(generator, PhraseStrength.Normal, 1000); //BenchmarkSecureGeneration(generator, PhraseStrength.Normal, 1000); //BenchmarkUtf8Generation(generator, PhraseStrength.Normal, 1000); //BenchmarkGeneration(generator, PhraseStrength.Strong, 1000); //BenchmarkGeneration(generator, PhraseStrength.Insane, 1000); //BenchmarkGeneration(generator, PhraseStrength.Random, 1000); // Test all combinations of phrase combinations / textual parsing. //TestAllStrengthsAndOutputs(generator); // Test spaces, no spaces and custom delimiter. //GenerateDelimiterSamples(PhraseStrength.Random, generator, 5, " "); //GenerateDelimiterSamples(PhraseStrength.Random, generator, 5, ""); //GenerateDelimiterSamples(PhraseStrength.Random, generator, 5, "."); //GenerateDelimiterSamples(PhraseStrength.Random, generator, 5, "✶"); // Generate statistics. //WriteAllStatistics(generator); // This is used to tinker with custom clauses, probabilities, grammar, etc. //TinkerWithCustomClause(generator); // Other test cases. //TestBitbucketIssue15(generator); //TestBitbucketIssue16(generator); // Longer benchmarks. //BenchmarkGeneration(generator, PhraseStrength.Normal, 10000); //BenchmarkGeneration(generator, PhraseStrength.Strong, 10000); //BenchmarkGeneration(generator, PhraseStrength.Insane, 10000); // Random function distribution tests. //TestCoinFlip(SeededRandom()); //TestWeightedCoinFlip(SeededRandom(), 1, 1); //TestNextInt32(SeededRandom(), 4); //TestNextInt32(SeededRandom(), 15); //TestNextInt32(SeededRandom(), 50); //TestNextInt32(SeededRandom(), 64); //TestNextInt32(SeededRandom(), 256); //TestNextInt32(SeededRandom(), 1296); // TODO: Test load an alternate dictionary loader. // Test the config form. #if NETFRAMEWORK // No WinForms in NetCore //TestConfigForm(generator); #endif // Test mutators. //GenerateMutatedSamples(PhraseStrength.Random, generator, 10, new IMutator[] { new UppercaseRunMutator() }); //GenerateMutatedSamples(PhraseStrength.Random, generator, 10, new IMutator[] { new NumericMutator() }); //GenerateMutatedSamples(PhraseStrength.Random, generator, 10, new IMutator[] { new ConstantMutator() }); // Test loading the default dictionary. //var defaultDictSw = System.Diagnostics.Stopwatch.StartNew(); //var defaultDict = MurrayGrant.ReadablePassphrase.Dictionaries.Default.Load(); //defaultDictSw.Stop(); //Console.WriteLine("Loaded default dictionary from assembly resource with {0:N0} words in {1:N2}ms ({2:N3} words / sec)", defaultDict.Count, defaultDictSw.Elapsed.TotalMilliseconds, defaultDict.Count / defaultDictSw.Elapsed.TotalSeconds); //var easyCreatedGenerator = MurrayGrant.ReadablePassphrase.Generator.Create(); //Console.WriteLine("Loaded generator from Generator.Create() with default dictionary of {0:N0} words.", easyCreatedGenerator.Dictionary.Count); }