From 5c44f860f1182f8cbf440dc7dc6e10711bfb2bc6 Mon Sep 17 00:00:00 2001 From: marcinzelent Date: Sat, 17 Mar 2018 19:33:55 +0100 Subject: Prettier output --- DistributedPasswordCracker.Server/Program.cs | 35 ++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 7 deletions(-) (limited to 'DistributedPasswordCracker.Server') diff --git a/DistributedPasswordCracker.Server/Program.cs b/DistributedPasswordCracker.Server/Program.cs index ef8f93f..0b4480f 100644 --- a/DistributedPasswordCracker.Server/Program.cs +++ b/DistributedPasswordCracker.Server/Program.cs @@ -16,16 +16,28 @@ namespace DistributedPasswordCracker.Server static void Main(string[] args) { + Console.Write("Reading passwords file... "); List userInfos = PasswordFileHandler.ReadPasswordFile("passwords.txt"); - List allChunks = new List(); string users = ""; foreach (UserInfo u in userInfos) users += u + "|"; + if (users != "") Console.Write("OK\n"); + else Console.Write("FAILED\n"); + Console.Write("Reading dictionary file... "); var dictionary = File.ReadAllText("dictionary.txt"); dictionary = dictionary.Replace('\n', '|'); + if (dictionary != "") Console.Write("OK\n"); + else Console.Write("FAILED\n"); + + Console.Write("Splitting dictionary... "); var splitDictionary = SplitDictionary(dictionary); + if (splitDictionary.Length != 0) Console.Write("OK\n"); + else Console.Write("FAILED\n"); + + List allChunks = new List(); + for (int i = 0; i < splitDictionary.GetLength(0); i++) { StringBuilder chunk = new StringBuilder(); @@ -36,11 +48,11 @@ namespace DistributedPasswordCracker.Server } allChunks.Add(chunk.ToString()); } - + + Console.Write("Starting server... "); TcpListener serverSocket = new TcpListener(IPAddress.Any, 7777); serverSocket.Start(); - - Console.WriteLine("Server started."); + Console.Write("OK\n"); List> tasks = new List>(); @@ -49,12 +61,21 @@ namespace DistributedPasswordCracker.Server var chunk = allChunks[i]; tasks.Add(Task.Run(()=>RunClientAsync(serverSocket, users, chunk))); } + Console.Write("Waiting for clients' response... "); string[] result = Task.WhenAll(tasks).Result; + Console.Write("OK\n\n"); + string output = ""; foreach (string s in result) - Console.WriteLine(s); - + output += s; + + output = output.Replace(':', ' ').Replace('|', '\n'); + Console.Write(output); + serverSocket.Stop(); + + Console.Write("\nPress any key to exit..."); + Console.ReadKey(); } private static string[,] SplitDictionary(string dictionary) @@ -81,7 +102,7 @@ namespace DistributedPasswordCracker.Server private async static Task RunClientAsync(TcpListener serverSocket, string pass, string chunk) { - TcpClient connectionSocket = serverSocket.AcceptTcpClient();; + TcpClient connectionSocket = serverSocket.AcceptTcpClient(); Stream ns = connectionSocket.GetStream(); StreamReader sr = new StreamReader(ns); StreamWriter sw = new StreamWriter(ns) -- cgit v1.2.3