Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace PasswordTableTest
- {
- static class Program
- {
- static void Main(string[] args)
- {
- // Create a list of strings defining the charset for each index.
- var charsets = new List<string>
- { "abcdef", "defghi", "ghijkl", "jklmno", "mnopqrstuvwxyz", "pq234r", "st2342u" };
- // Get the IEnumerable (note: This does not generate the permutations, just gives an IEnumerable to enumerate through thema ll)
- var cp = CartesianProduct(charsets);
- // Print them out
- string row = "";
- foreach (string s in cp.Select(set => set.Aggregate("", (a, b) => a + b)))
- {
- row += s + ' ';
- if (row.Length > 60)
- {
- Console.WriteLine(row);
- row = "";
- }
- }
- Console.ReadKey();
- }
- public static IEnumerable<IEnumerable<T>> CartesianProduct<T>(this IEnumerable<IEnumerable<T>> sequences)
- {
- IEnumerable<IEnumerable<T>> result = new[] { Enumerable.Empty<T>() };
- return sequences.Aggregate(result, (current, s) =>
- (from seq in current from item in s select seq.Concat(new[] {item})));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement