Created
December 25, 2012 16:48
-
-
Save nk0t/4374149 to your computer and use it in GitHub Desktop.
総当りプログラム
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace Bruteforce | |
{ | |
class Program | |
{ | |
const string letters = "0123456789abcdef"; | |
static void Main(string[] args) | |
{ | |
foreach (var str in Bruteforce(letters, 4)) | |
{ | |
Console.WriteLine(str); | |
} | |
} | |
public static IEnumerable<string> Bruteforce(string letters,int len) | |
{ | |
var num = new List<int>(new[] { -1 }); | |
while (true) | |
{ | |
int p = 0; | |
while (true) | |
{ | |
if (p == num.Count) | |
num.Add(0); | |
if (num.Count > len) | |
yield break; | |
num[p]++; | |
if (num[p] >= letters.Length) | |
{ | |
num[p] = 0; | |
p++; | |
continue; | |
} | |
break; | |
} | |
yield return new string(num.Select(s => letters[s]).Reverse().ToArray()); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment