aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarcinzelent <zelent.marcin@gmail.com>2018-03-17 19:33:55 +0100
committermarcinzelent <zelent.marcin@gmail.com>2018-03-17 19:33:55 +0100
commit5c44f860f1182f8cbf440dc7dc6e10711bfb2bc6 (patch)
treebd4c9ba291c170393bc45ed84ebd0ad89b96dfef
parent7229b4a2ab78529f77bdf589aebf45e236598e0e (diff)
Prettier output
-rw-r--r--DistributedPasswordCracker.Client/Program.cs11
-rw-r--r--DistributedPasswordCracker.Server/Program.cs35
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<Task<string>> tasks = new List<Task<string>>();
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<string> 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<UserInfo> userInfos = PasswordFileHandler.ReadPasswordFile("passwords.txt");
- List<string> allChunks = new List<string>();
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<string> allChunks = new List<string>();
+
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<Task<string>> tasks = new List<Task<string>>();
@@ -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<string> 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)