using System; using System.Collections.Generic; using System.Linq; using System.Threading; namespace zad3._1 { class Program { static public string password; static public string password2; static List buffor = new List(); static Thread producer; static Thread consumer; static Thread temp; //bruteforce static void generujHaslo(int length) { Random random = new Random(); char[] tab = new char[length]; for (int i = 0; i < length; i++) { tab[i] = (char)random.Next(97, 122); } password = new String(tab); Console.WriteLine(password); } static public void tempfunction() { buffor.Add("a"); producer = new Thread(new ThreadStart(producerfunction)); consumer = new Thread(new ThreadStart(consumerfunction)); producer.Start(); consumer.Start(); while (true) { if (!producer.IsAlive) { consumer.Abort(); producer.Abort(); break; } } } static public void producerfunction() { char[] tab = new char[password.Length]; Random random = new Random(); while (true) { for (int j = 0; j < password.Length; j++) { tab[j] = (char)random.Next(97, 122); } password2 = new String(tab); Console.WriteLine("Producer: generated password " + password2); buffor.Add(password2); Console.WriteLine("Buffor: Password added. Capacity: " + buffor.Capacity); Thread.Sleep(1); } } static public void consumerfunction() { while (true) { if (buffor.First() != password) { Console.WriteLine("Consumer: Wrong password " + buffor.First()); buffor.Remove(buffor.First()); } else { Console.WriteLine("Consumer: Password Guessed - " + buffor.First()); producer.Abort(); } Thread.Sleep(2); } } static void Main(string[] args) { generujHaslo(3); temp = new Thread(new ThreadStart(tempfunction)); temp.Start(); Console.ReadLine(); } } }