usingSystem;usingSystem.Collections.Generic;usingSystem.IO;usingSystem.Net.Sockets;usingSystem.Threading.Tasks;usingDistributedPasswordCracker.Client.Models;namespaceDistributedPasswordCracker.Client{classProgram{constintNumberOfTasks=5;privatestaticStreamReadersr;privatestaticStreamWritersw;staticvoidMain(string[]args){Console.Write("Connecting to server... ");TcpClientclientSocket=newTcpClient("127.0.0.1",7777);NetworkStreamns=clientSocket.GetStream();Console.Write("OK\n");sr=newStreamReader(ns);sw=newStreamWriter(ns);sw.AutoFlush=true;Console.Write("Getting data from the server... ");stringdata=GetData();if(data!="")Console.Write("OK\n");Console.Write("Parsing data... ");stringdictionary=ParseData(data);if(dictionary!="")Console.Write("OK\n");Console.Write("Splitting dictionary... ");string[,]splitDictionary=SplitDictionary(dictionary);if(splitDictionary[0,0]!="")Console.Write("OK\n");Console.WriteLine("Cracking...");List<Task<string>>tasks=newList<Task<string>>();for(inti=0;i<NumberOfTasks;i++){introwLength=splitDictionary.GetLength(1);string[]chunk=newstring[rowLength];for(intj=0;j<rowLength;j++)chunk[j]=splitDictionary[i,j];tasks.Add(Task.Run(()=>DecryptPassword(chunk)));}varresult=Task.WhenAll(tasks).Result;if(result.Length!=0){stringoutput="";for(inti=0;i<result.Length;i++)output+=result[i];Console.Write("Sending results to server...");sw.WriteLine(output);Console.Write("OK\n");}else{Console.Write("FAILED\n");Console.Write("Sending notification to server...");sw.WriteLine("No passwords cracked!");Console.Write("OK\n");}Console.WriteLine("Press any key to exit...");Console.ReadKey();}privatestaticstringGetData(){stringdata="";while(true){stringmessage=sr.ReadLine();if(message!="")data+=message+"\n";elsebreak;}returndata;}privatestaticstringParseData(stringdata){varsplitData=data.Split('\n');if(splitData[0]=="DPCP 1.0"){splitData[1]=splitData[1].Replace('|','\n');File.WriteAllText("passwords.txt",splitData[1]);File.WriteAllText("dictionary.txt",splitData[2]);}returnsplitData[2];}privatestaticstring[,]SplitDictionary(stringdictionary){string[]dicWords=dictionary.Split('|');intdicWordsLength=dicWords.Length;string[,]splitDictionary=newstring[NumberOfTasks,dicWordsLength/NumberOfTasks];intoffset=0;intj=0;for(inti=0;i<NumberOfTasks;i++){while(j<dicWordsLength/NumberOfTasks){splitDictionary[i,j]=dicWords[j+offset];j++;}offset+=dicWordsLength/NumberOfTasks;j=0;}returnsplitDictionary;}privatestaticasyncTask<string>DecryptPassword(string[]dictionary){Crackingcracker=newCracking();varresult=cracker.RunCracking(dictionary);returnresult;}}}