commit 58e77c930a07c87b656d441b0019e8866749e308 Author: Kukks Date: Sun May 3 16:59:18 2020 +0200 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..14a4d8f --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +bin/ +obj/ +/packages/ +.idea diff --git a/VanityGenerator.sln b/VanityGenerator.sln new file mode 100644 index 0000000..2bc27e3 --- /dev/null +++ b/VanityGenerator.sln @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VanityGenerator", "VanityGenerator\VanityGenerator.csproj", "{FCC150E5-0933-4B94-89FA-EFEF07A7B776}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {FCC150E5-0933-4B94-89FA-EFEF07A7B776}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FCC150E5-0933-4B94-89FA-EFEF07A7B776}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FCC150E5-0933-4B94-89FA-EFEF07A7B776}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FCC150E5-0933-4B94-89FA-EFEF07A7B776}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/VanityGenerator/Program.cs b/VanityGenerator/Program.cs new file mode 100644 index 0000000..c8d5cb8 --- /dev/null +++ b/VanityGenerator/Program.cs @@ -0,0 +1,114 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Channels; +using System.Threading.Tasks; +using NBitcoin; + +namespace VanityGenerator +{ + class Program + { + private static readonly Channel<(string, string)> Found = Channel.CreateUnbounded<(string, string)>(); + + + static async Task Main(string[] args) + { + var toMatch = new List(); + while (true) + { + Console.Write($"Enter what to match for{(toMatch.Any()? " (or leave blank to start)": string.Empty)}:"); + var entry = Console.ReadLine(); + + + if (string.IsNullOrEmpty(entry) && toMatch.Any()) + { + Console.WriteLine($"Going to be searching for {string.Join(',', toMatch)}"); + break; + } + + toMatch.Add(entry); + + } + _ = WriteResults(); + _ = Hunt(GetSubset(toMatch)); + } + + private static IEnumerable GetSubset(IEnumerable matches) + { + return matches.SelectMany(s => + { + if (s.Length <= 4) + { + return new[] {s.ToLowerInvariant()}; + } + else + { + var result = new string[s.Length - 3]; + for (int x = 4; x <= s.Length; x++) + { + result[x - 4] = s.Substring(0, x).ToLowerInvariant(); + } + + return result; + } + }); + } + + private static async Task WriteResults() + { + while (await Found.Reader.WaitToReadAsync(CancellationToken.None)) + { + if (Found.Reader.TryRead(out var req)) + { + if (string.IsNullOrEmpty(req.Item1) || string.IsNullOrEmpty(req.Item2)) + { + continue; + } + + await File.WriteAllTextAsync(req.Item1 + ".txt", $"{req.Item1}{Environment.NewLine}{req.Item2}", + Encoding.UTF8, CancellationToken.None); + } + } + } + + private static async Task Hunt(IEnumerable toMatch) + { + while (true) + { + var k = new Key(); + var segwit = k.PubKey.GetAddress(ScriptPubKeyType.Segwit, Network.Main).ToString().ToLowerInvariant(); + var segwitp2sh = k.PubKey.GetAddress(ScriptPubKeyType.SegwitP2SH, Network.Main).ToString() + .ToLowerInvariant(); + var matchesNative = Matches(toMatch, segwit.Substring(4)); + var matchesP2SH = Matches(toMatch, segwitp2sh.Substring(1)); + if (matchesNative.Any() || matchesP2SH.Any()) + { + foreach (var s in matchesNative) + { + var fileName = $"{s} segwit addr={segwit}"; + var wif = k.GetWif(Network.Main).ToString(); + Console.WriteLine($"{fileName} wif={wif}"); + await Found.Writer.WriteAsync((fileName, wif)); + } + + foreach (var s in matchesP2SH) + { + var fileName = $"{s} p2sh addr={segwitp2sh}"; + var wif = k.GetWif(Network.Main).ToString(); + Console.WriteLine($"{fileName} wif={wif}"); + await Found.Writer.WriteAsync((fileName, wif)); + } + } + } + } + + private static string[] Matches(IEnumerable vanity, string address) + { + return vanity.Where(address.StartsWith).ToArray(); + } + } +} \ No newline at end of file diff --git a/VanityGenerator/VanityGenerator.csproj b/VanityGenerator/VanityGenerator.csproj new file mode 100644 index 0000000..b5317b6 --- /dev/null +++ b/VanityGenerator/VanityGenerator.csproj @@ -0,0 +1,12 @@ + + + + Exe + netcoreapp3.1 + + + + + + +