Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- class Program
- {
- const uint A = 0x41C64E6D;
- const uint C = 0x3039;
- const int InitialConsume = 2; //事前消費
- const int CompareCount = 10;
- static void Main()
- {
- Console.WriteLine("DQMJ2P 初期SEED絞り込みツール");
- Console.WriteLine();
- Console.Write("起動時間 (yyyy/MM/dd HH:mm:ss) 空欄 = 現在時刻: ");
- string timeInput = Console.ReadLine();
- DateTime baseTime;
- if (string.IsNullOrWhiteSpace(timeInput))
- {
- baseTime = DateTime.Now;
- }
- else
- {
- baseTime = DateTime.ParseExact(
- timeInput,
- "yyyy/MM/dd HH:mm:ss",
- CultureInfo.InvariantCulture
- );
- }
- Console.Write("観測値 (0~6 を10個まで、スペース区切り): ");
- string valueInput = Console.ReadLine();
- string[] tokens = valueInput.Split(' ', StringSplitOptions.RemoveEmptyEntries); //観測値のリスト
- List<int> observed = new List<int>();
- for (int i = 0; i < tokens.Length && i < CompareCount; i++)
- {
- observed.Add(int.Parse(tokens[i]));
- }
- Console.WriteLine();
- Console.WriteLine("Searching...");
- List<(uint init, uint current)> results = new List<(uint, uint)>();
- for (int sec = -60; sec <= 60; sec++) //±1分の範囲
- {
- DateTime t = baseTime.AddSeconds(sec);
- uint initSeed = TimeToSeed(t);
- uint seed = initSeed;
- for (int i = 0; i < InitialConsume; i++)
- {
- seed = Next(seed);
- }
- bool match = true;
- uint current = seed;
- for (int i = 0; i < observed.Count; i++)
- {
- current = Next(current);
- int value = (int)((current >> 16) % 7);
- if (value == observed[i]) {}
- else
- {
- match = false;
- break;
- }
- }
- if (match)
- {
- results.Add((initSeed, current));
- }
- }
- Console.WriteLine();
- Console.WriteLine("Found " + results.Count + " candidates");
- for (int i = 0; i < results.Count; i++)
- {
- Console.WriteLine(
- "InitSeed=0x" + results[i].init.ToString("X8") +
- " CurrentSeed=0x" + results[i].current.ToString("X8"));
- }
- }
- static uint Next(uint seed)
- {
- return unchecked(A * seed + C);
- }
- static uint TimeToSeed(DateTime time)
- {
- DateTime baseTime = new DateTime(
- 2000, 1, 1, 0, 0, 0,
- DateTimeKind.Local
- );
- TimeSpan span = time - baseTime;
- long seconds = (long)span.TotalSeconds;
- return (uint)seconds;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment