Example #1
0
        static void Main(string[] args)
        {
            Console.Title = "VIRCOIN Node";
            Thread thr1 = new Thread(licznik);
            Thread thr2 = new Thread(menu);

            Console.WriteLine("VIRCOIN");
            // case number one (difficulty = 2)
            int difficulty = 5;
            int finishTime = CurrentTime + 15;

            thr1.Start();
            thr2.Start();
            do
            {
                ChallengeResult result = SolveTheChallenge(RandomStringGenerator.GenerateByLen(10), difficulty);
                poprawne++;
            } while (1 == 1);
            //} while (CurrentTime < finishTime);
            //Console.WriteLine($"Total number of solutions found for (difficulty = 2): {numberOfSolutionsFound}");
            //ChallengeResult result = SolveTheChallenge(RandomStringGenerator.GenerateByLen(10), difficulty);
            //Console.WriteLine(result.SolveHash);
            //Console.WriteLine(result.SolveString);

            //Console.ReadKey();
        }
Example #2
0
        private static ChallengeResult SolveTheChallenge(string challengeString, int difficulty)
        {
            var    challengeResult = new ChallengeResult();
            string expectedResult  = new string('0', difficulty); // if the difficulty = 4 the expectedResult will be = '0000'
            var    stopwatch       = new Stopwatch();

            stopwatch.Start(); // doing time measurement
            do
            {
                challengeResult.NumberOfIterations++;                                                            // counting the number of iterations
                challengeResult.SolveString = challengeString + RandomStringGenerator.GenerateByLen(10);         // generating random string to test it
                challengeResult.SolveHash   = Sha256Generator.GenerateSha256String(challengeResult.SolveString); // generating sha-256 from the random string
                wszystkie++;
                wszystkieOgolem++;
            } while (!challengeResult.SolveHash.StartsWith(expectedResult)); // checking if we found a solution
            challengeResult.SolveSeconds = stopwatch.Elapsed.TotalSeconds;
            return(challengeResult);
        }