From 5c44f860f1182f8cbf440dc7dc6e10711bfb2bc6 Mon Sep 17 00:00:00 2001 From: marcinzelent Date: Sat, 17 Mar 2018 19:33:55 +0100 Subject: Prettier output --- DistributedPasswordCracker.Client/Program.cs | 11 +++++---- DistributedPasswordCracker.Server/Program.cs | 35 ++++++++++++++++++++++------ 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/DistributedPasswordCracker.Client/Program.cs b/DistributedPasswordCracker.Client/Program.cs index 197f62a..9248f53 100644 --- a/DistributedPasswordCracker.Client/Program.cs +++ b/DistributedPasswordCracker.Client/Program.cs @@ -36,7 +36,7 @@ namespace DistributedPasswordCracker.Client string[,] splitDictionary = SplitDictionary(dictionary); if (splitDictionary[0,0] != "") Console.Write("OK\n"); - Console.WriteLine("Cracking..."); + Console.Write("Cracking... \n\n"); List> tasks = new List>(); for(int i = 0; i < NumberOfTasks; i++) { @@ -54,7 +54,7 @@ namespace DistributedPasswordCracker.Client for (int i = 0; i < result.Length; i++) output += result[i]; - Console.Write("Sending results to server..."); + Console.Write("\nSending results to server..."); sw.WriteLine(output); Console.Write("OK\n"); } @@ -62,10 +62,11 @@ namespace DistributedPasswordCracker.Client { Console.Write("FAILED\n"); Console.Write("Sending notification to server..."); - sw.WriteLine("No passwords cracked!"); + sw.WriteLine(); Console.Write("OK\n"); } - Console.WriteLine("Press any key to exit..."); + + Console.Write("\nPress any key to exit..."); Console.ReadKey(); } @@ -119,7 +120,7 @@ namespace DistributedPasswordCracker.Client return splitDictionary; } - private static async Task DecryptPassword(string[] dictionary) + private static string DecryptPassword(string[] dictionary) { Cracking cracker = new Cracking(); var result = cracker.RunCracking(dictionary); 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