Created
May 1, 2013 21:46
-
-
Save sjparkinson/5498642 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
void Main() | |
{ | |
Parallel.For(0, 9999999, (pin, loop) => | |
{ | |
using(var sha1 = new SHA1Cng()) | |
using(var sha256 = new SHA256Cng()) | |
using(var md5 = new MD5Cng()) | |
{ | |
byte[] data = Encoding.ASCII.GetBytes(pin.ToString("D7")); | |
if (GetHexResult(data, sha1).Substring(0, 2) == "F1" | |
&& GetHexResult(data, sha256).Substring(30, 2) == "91" | |
&& GetHexResult(data, md5).Substring(30, 2) == "5A") | |
{ | |
pin.ToString("D7").Dump(); | |
loop.Stop(); | |
} | |
} | |
}); | |
} | |
// Define other methods and classes here | |
public static string GetHexResult(byte[] data, HashAlgorithm algorithm) | |
{ | |
return algorithm.ComputeHash(data).ToHexString(); | |
} | |
public static class MyExtensions | |
{ | |
// Write custom extension methods here. They will be available to all queries. | |
// Source: http://stackoverflow.com/a/14333437 | |
public static string ToHexString(this byte[] bytes) | |
{ | |
if (bytes == null) | |
{ | |
throw new ArgumentNullException("bytes", "The byte array was null."); | |
} | |
int b; | |
char[] chars = new char[bytes.Length * 2]; | |
for (int i = 0; i < bytes.Length; i++) | |
{ | |
b = bytes[i] >> 4; | |
chars[i * 2] = (char)(55 + b + (((b - 10) >> 31) & -7)); | |
b = bytes[i] & 0xF; | |
chars[i * 2 + 1] = (char)(55 + b + (((b - 10) >> 31) & -7)); | |
} | |
return new string(chars); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment