Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Security.Cryptography;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- namespace ConsoleApplication1
- {
- struct Stats
- {
- public string LastValue;
- public long Frist;
- public long Last;
- public long Progress;
- public double Speed;
- }
- class Worker
- {
- public bool Stop { get; set; }
- public Stats stats = new Stats();
- public byte[] Target { get; set; }
- public bool Success { get; private set; }
- public String Value { get; private set; }
- long _start, _stop;
- public Worker(long start, long stop, byte[] target)
- {
- _start = start;
- _stop = stop;
- stats.Progress = start;
- stats.Frist = start;
- stats.Last = stop;
- stats.LastValue = "";
- Target = target;
- Stop = false;
- }
- public void Start()
- {
- perm p = new perm(stats.Frist);
- byte[] hash = new byte[16];
- Stopwatch watch = new Stopwatch();
- watch.Start();
- hash = Converter.HexToByteArray("202cb962ac59075b964b07152d234b70");
- for (long i = _start; i < _stop; i++)
- {
- hash = MD5.Create().ComputeHash(Encoding.Default.GetBytes(p.ValueAsCharArray));
- //MD5.Create().ComputeHash(Encoding.Default.GetBytes(p.ValueAsCharArray)).CopyTo(hash, 0);
- if (hash.SequenceEqual(Target))
- {
- Success = true;
- Value = p.Value;
- break;
- }
- p.Next();
- if (i % 10000 == 0)
- {
- //GC.Collect();
- try
- {
- stats.Speed = 1000000 / watch.ElapsedMilliseconds; //interval * 1000
- }
- catch (DivideByZeroException e)
- {
- stats.Speed = 0;
- }
- watch.Restart();
- stats.Progress = i;
- stats.LastValue = p.Value;
- if (Stop) break;
- }
- }
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- DateTime nu = DateTime.Now;
- string s = Workworkwork();
- Console.Clear();
- Console.WriteLine(s);
- Console.WriteLine((DateTime.Now - nu).TotalMilliseconds);
- Console.ReadKey();
- }
- public static string Workworkwork()
- {
- int interval = 500000, iCount = 0;
- int threadCount = Environment.ProcessorCount - 1;
- // 63363e9525ee0fe5ce26689544a7368d // hejja
- // 365beccc2337a59965fd189105f1d4f3 // armera
- // 05b972dcf28374406d13e879724bfe3b // hejsan
- byte[] target = Converter.HexToByteArray("63363e9525ee0fe5ce26689544a7368d");
- Worker[] workers = new Worker[threadCount];
- for (int i = 0; i < threadCount; i++)
- workers[i] = new Worker(iCount++ * interval, iCount * interval, target);
- Thread[] threads = new Thread[threadCount];
- for (int i = 0; i < threadCount; i++)
- threads[i] = new Thread(new ThreadStart(workers[i].Start));
- foreach (Thread t in threads)
- t.Start();
- double percent, sumSpeed;
- Stopwatch watch = new Stopwatch();
- watch.Start();
- while (true)
- {
- sumSpeed = 0;
- for (int i = 0; i < threadCount; i++)
- {
- sumSpeed += workers[i].stats.Speed;
- Console.CursorLeft = 2;
- Console.CursorTop = 3 + i * 3;
- Console.Write("Thread " + i);
- Console.WriteLine(" n: {0:n0} = {1} @{2:n0}/s ",
- workers[i].stats.Progress, workers[i].stats.LastValue, workers[i].stats.Speed);
- percent = 100 * (workers[i].stats.Progress - workers[i].stats.Frist) / (workers[i].stats.Last - workers[i].stats.Frist);
- Console.CursorLeft = 2;
- Console.BackgroundColor = ConsoleColor.DarkGray;
- Console.Write(new string(' ', 76));
- Console.CursorLeft = 2;
- Console.BackgroundColor = ConsoleColor.Cyan;
- Console.Write(new string(' ', (int)(percent / 1.3)));
- Console.ResetColor();
- if (!threads[i].IsAlive)
- {
- if (workers[i].Success)
- {
- foreach (Worker w in workers)
- w.Stop = true;
- return workers[i].Value;
- }
- else
- {
- workers[i] = new Worker(iCount++ * interval, iCount * interval, target);
- threads[i] = new Thread(new ThreadStart(workers[i].Start));
- threads[i].Start();
- }
- }
- }
- Console.CursorTop = 0;
- Console.CursorLeft = 2;
- Console.WriteLine("{0,-10}{1,-20:n0}{2,46}", "Hashes/s:", sumSpeed, watch.Elapsed.ToString(@"hh\:mm\:ss"));
- Thread.Sleep(200);
- }
- }
- }
- class perm
- {
- static char[] _alpha = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".ToCharArray();
- //static char[] _alpha = "0123456789".ToCharArray();
- char[] _value;
- public string Value
- {
- get
- {
- return new String(_value);
- }
- private set
- {
- _value = value.ToCharArray();
- }
- }
- public char[] ValueAsCharArray
- {
- get { return _value; }
- private set { }
- }
- public static char[] l2c(long lng)
- {
- long l = lng;
- int permBase = _alpha.Count();
- int pow = 0;
- long tmp = 0, prev = 0;
- do
- {
- prev = tmp;
- pow++;
- tmp += (long)Math.Pow(permBase, pow);
- } while (l >= tmp);
- if (pow > 1)
- l -= prev;
- char[] cArr = new char[pow];
- for (int i = pow - 1; i >= 0; i--)
- {
- int j = 0;
- long val = (long)Math.Pow(permBase, i);
- while (l >= val)
- {
- l -= val;
- j++;
- }
- cArr[pow - i - 1] = _alpha[j];
- }
- return cArr;
- }
- public perm(long val)
- {
- _value = l2c(val);
- }
- public char[] Next()
- {
- int i = 0, j = 0;
- for (i = _value.Length - 1; i >= 0; i--)
- {
- for (j = 0; j < _alpha.Length; j++)
- if (_alpha[j] == _value[i]) break;
- if (++j != _alpha.Length)
- {
- _value[i] = _alpha[j];
- break;
- }
- else
- {
- _value[i] = _alpha[0];
- }
- }
- if (i == -1 && j == _alpha.Length)
- {
- Array.Resize(ref _value, _value.Length + 1);
- _value[_value.Length - 1] = _alpha[0];
- }
- return _value;
- }
- }
- static class Converter
- {
- public static byte[] HexToByteArray(string hex)
- {
- int len = hex.Length;
- byte[] bytes = new byte[len / 2];
- for (int i = 0; i < len; i += 2)
- bytes[i / 2] = Convert.ToByte(hex.Substring(i, 2), 16);
- return bytes;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement