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
<String> buffor
= new List
<string>();
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();
}
}
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}