From 017da9023af14430adc165b524ee50ae37ba9f5e Mon Sep 17 00:00:00 2001 From: marcinzelent Date: Sat, 17 Mar 2018 00:37:41 -0700 Subject: Changes --- .../.vs/PasswordCrackerDistributed/v15/.suo | Bin 0 -> 70144 bytes .../v15/Server/sqlite3/db.lock | 0 .../v15/Server/sqlite3/storage.ide | Bin 0 -> 450560 bytes .../PasswordCrackerServer/Program.cs | 154 ++++++--------------- .../bin/Debug/PasswordCrackerServer.exe | Bin 13312 -> 12288 bytes .../bin/Debug/PasswordCrackerServer.pdb | Bin 28160 -> 28160 bytes .../PasswordCrackerServer/clientConnection.cs | 32 ++--- ...ordCrackerServer.csproj.CoreCompileInputs.cache | 1 + ...sswordCrackerServer.csproj.FileListAbsolute.txt | 7 + ...ckerServer.csprojResolveAssemblyReference.cache | Bin 1904 -> 9828 bytes .../obj/Debug/PasswordCrackerServer.exe | Bin 13312 -> 12288 bytes .../obj/Debug/PasswordCrackerServer.pdb | Bin 28160 -> 28160 bytes ...ordCrackerServer.csproj.CoreCompileInputs.cache | 1 + 13 files changed, 65 insertions(+), 130 deletions(-) create mode 100644 PasswordCrackerDistributed/.vs/PasswordCrackerDistributed/v15/.suo create mode 100644 PasswordCrackerDistributed/.vs/PasswordCrackerDistributed/v15/Server/sqlite3/db.lock create mode 100644 PasswordCrackerDistributed/.vs/PasswordCrackerDistributed/v15/Server/sqlite3/storage.ide create mode 100644 PasswordCrackerDistributed/PasswordCrackerServer/obj/Debug/PasswordCrackerServer.csproj.CoreCompileInputs.cache create mode 100644 PasswordCrackerDistributed/PasswordCrackerServer/obj/Release/PasswordCrackerServer.csproj.CoreCompileInputs.cache (limited to 'PasswordCrackerDistributed') diff --git a/PasswordCrackerDistributed/.vs/PasswordCrackerDistributed/v15/.suo b/PasswordCrackerDistributed/.vs/PasswordCrackerDistributed/v15/.suo new file mode 100644 index 0000000..cb3b2d3 Binary files /dev/null and b/PasswordCrackerDistributed/.vs/PasswordCrackerDistributed/v15/.suo differ diff --git a/PasswordCrackerDistributed/.vs/PasswordCrackerDistributed/v15/Server/sqlite3/db.lock b/PasswordCrackerDistributed/.vs/PasswordCrackerDistributed/v15/Server/sqlite3/db.lock new file mode 100644 index 0000000..e69de29 diff --git a/PasswordCrackerDistributed/.vs/PasswordCrackerDistributed/v15/Server/sqlite3/storage.ide b/PasswordCrackerDistributed/.vs/PasswordCrackerDistributed/v15/Server/sqlite3/storage.ide new file mode 100644 index 0000000..8081bae Binary files /dev/null and b/PasswordCrackerDistributed/.vs/PasswordCrackerDistributed/v15/Server/sqlite3/storage.ide differ diff --git a/PasswordCrackerDistributed/PasswordCrackerServer/Program.cs b/PasswordCrackerDistributed/PasswordCrackerServer/Program.cs index 06b5414..4ae77a3 100644 --- a/PasswordCrackerDistributed/PasswordCrackerServer/Program.cs +++ b/PasswordCrackerDistributed/PasswordCrackerServer/Program.cs @@ -1,166 +1,96 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; using System.Net; using System.Net.Sockets; using System.Text; using System.Threading.Tasks; -using System.Threading; namespace PasswordCrackerServer { class Program { + static int NumberOfClients = 1; + static void Main(string[] args) { List userInfos = PasswordFileHandler.ReadPasswordFile("passwords.txt"); List clients = new List(); - List allchunks; + List allChunks = new List(); string users = ""; foreach (UserInfo u in userInfos) - { users += u + "|"; - } - if ( - File.Exists("chunk0.txt") - && - File.Exists("chunk1.txt") - && - File.Exists("chunk2.txt") - && - File.Exists("chunk3.txt") - && - File.Exists("chunk4.txt") - - ) - { - string chunk1String = File.ReadAllText("chunk0.txt"); - string chunk2String = File.ReadAllText("chunk1.txt"); - string chunk3String = File.ReadAllText("chunk2.txt"); - string chunk4String = File.ReadAllText("chunk3.txt"); - string chunk5String = File.ReadAllText("chunk4.txt"); - - allchunks = new List() - { - chunk1String, - chunk2String, - chunk3String, - chunk4String, - chunk5String - }; - } - else + var dictionary = File.ReadAllText("webster-dictionary.txt"); + dictionary = dictionary.Replace("\r\n", "|"); + var splitDictionary = SplitDictionary(dictionary); + for (int i = 0; i < splitDictionary.GetLength(0); i++) { - List words = new List(); - - using (FileStream fs = new FileStream("webster-dictionary.txt", FileMode.Open, FileAccess.Read)) - - using (StreamReader dictionary = new StreamReader(fs)) - { - while (!dictionary.EndOfStream) - { - words.Add(dictionary.ReadLine()); - } - } - - - List chunk1 = new List(words.GetRange(0, 65000)); - string chunk1String = ""; - foreach (string s1 in chunk1) - { - chunk1String += s1 + "|"; - } - List chunk2 = new List(words.GetRange(65000, 65000)); - string chunk2String = ""; - foreach (string s2 in chunk2) - { - chunk2String += s2 + "|"; - } - List chunk3 = new List(words.GetRange(130000, 65000)); - string chunk3String = ""; - foreach (string s3 in chunk3) - { - chunk3String += s3 + "|"; - } - List chunk4 = new List(words.GetRange(195000, 65000)); - string chunk4String = ""; - foreach (string s4 in chunk4) - { - chunk4String += s4 + "|"; - } - List chunk5 = new List(words.GetRange(260000, 51141)); - string chunk5String = "" + " "; - foreach (string s5 in chunk5) - { - chunk5String += s5 + "|"; - } - allchunks = new List() - { - chunk1String, - chunk2String, - chunk3String, - chunk4String, - chunk5String - }; - - - string path = "chunk"; - - for (int i = 0; i < 5; i++) + StringBuilder chunk = new StringBuilder(); + for (int j = 0; j < splitDictionary.GetLength(1); j++) { - if (!File.Exists(path + i + ".txt")) - { - File.WriteAllText(path + i + ".txt", allchunks[i]); - } + chunk.Append(splitDictionary[i, j]); + chunk.Append('|'); } + allChunks.Add(chunk.ToString()); } - - - IPAddress ip = IPAddress.Any; TcpListener serversocket = new TcpListener(ip, 6789); serversocket.Start(); - Console.WriteLine("Server started"); + Console.WriteLine("Server started."); int counter = 0; while (true) { - if (clients.Count == 5) + if (clients.Count == NumberOfClients) { string[] returnedResult = RunAsync(clients).Result; foreach (string s in returnedResult) - { Console.WriteLine(s); - } } else { TcpClient connectionSocket = serversocket.AcceptTcpClient(); - Console.WriteLine("Server activated"); + Console.WriteLine("Client connected."); - clients.Add(new clientConnection(connectionSocket, allchunks[counter], users)); - counter ++; + clients.Add(new clientConnection(connectionSocket, allChunks[counter], users)); + counter++; } } serversocket.Stop(); } - public static async Task RunAsync(List clients) + private static string[,] SplitDictionary(string dictionary) { + string[] dicWords = dictionary.Split('|'); + int dicWordsLength = dicWords.Length; + string[,] splitDictionary = new string[NumberOfClients, dicWordsLength / NumberOfClients]; + int offset = 0; + int j = 0; + + for (int i = 0; i < NumberOfClients; i++) + { + while (j < dicWordsLength / NumberOfClients) + { + splitDictionary[i, j] = dicWords[j + offset]; + j++; + } + offset += dicWordsLength / NumberOfClients; + j = 0; + } + return splitDictionary; + } - var C1task = clients[0]; - var C2task = clients[1]; - var C3task = clients[2]; - var C4task = clients[3]; - var C5task = clients[4]; - + public static async Task RunAsync(List clients) + { + List> tasks = new List>(); + for (int i = 0; i < NumberOfClients; i++) + tasks[i] = clients[i].SendToClient(); - string[] result = await Task.WhenAll(C1task.Doit(), C2task.Doit() ,C3task.Doit(), C4task.Doit(), C5task.Doit()); + string[] result = await Task.WhenAll(tasks); /* var C1 = await C1task; diff --git a/PasswordCrackerDistributed/PasswordCrackerServer/bin/Debug/PasswordCrackerServer.exe b/PasswordCrackerDistributed/PasswordCrackerServer/bin/Debug/PasswordCrackerServer.exe index 9a74985..477dd30 100644 Binary files a/PasswordCrackerDistributed/PasswordCrackerServer/bin/Debug/PasswordCrackerServer.exe and b/PasswordCrackerDistributed/PasswordCrackerServer/bin/Debug/PasswordCrackerServer.exe differ diff --git a/PasswordCrackerDistributed/PasswordCrackerServer/bin/Debug/PasswordCrackerServer.pdb b/PasswordCrackerDistributed/PasswordCrackerServer/bin/Debug/PasswordCrackerServer.pdb index 20c72ef..4ba808c 100644 Binary files a/PasswordCrackerDistributed/PasswordCrackerServer/bin/Debug/PasswordCrackerServer.pdb and b/PasswordCrackerDistributed/PasswordCrackerServer/bin/Debug/PasswordCrackerServer.pdb differ diff --git a/PasswordCrackerDistributed/PasswordCrackerServer/clientConnection.cs b/PasswordCrackerDistributed/PasswordCrackerServer/clientConnection.cs index dc36679..c99d0be 100644 --- a/PasswordCrackerDistributed/PasswordCrackerServer/clientConnection.cs +++ b/PasswordCrackerDistributed/PasswordCrackerServer/clientConnection.cs @@ -1,37 +1,33 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; +using System.IO; using System.Net.Sockets; -using System.Text; using System.Threading.Tasks; namespace PasswordCrackerServer { class clientConnection { - public TcpClient connectionSocket { get; set; } - public string chunk { get; set; } - - public string pass { get; set; } + public TcpClient ConnectionSocket { get; set; } + public string Chunk { get; set; } + public string Pass { get; set; } public clientConnection(TcpClient connectionSocket, string chunk, string pass) { - this.connectionSocket = connectionSocket; - this.chunk = chunk; - this.pass = pass; + ConnectionSocket = connectionSocket; + Chunk = chunk; + Pass = pass; } - public async Task Doit() + public async Task SendToClient() { - Stream ns = connectionSocket.GetStream(); + Stream ns = ConnectionSocket.GetStream(); StreamReader sr = new StreamReader(ns); + StreamWriter sw = new StreamWriter(ns) + { + AutoFlush = true + }; - StreamWriter sw = new StreamWriter(ns); - sw.AutoFlush = true; - - sw.WriteLine($"DPCP 1.0\n{pass}\n{chunk}\n\n"); + sw.WriteLine($"DPCP 1.0\n{Pass}\n{Chunk}\n\n"); //sw.WriteLine(pass); //sw.WriteLine(chunk); diff --git a/PasswordCrackerDistributed/PasswordCrackerServer/obj/Debug/PasswordCrackerServer.csproj.CoreCompileInputs.cache b/PasswordCrackerDistributed/PasswordCrackerServer/obj/Debug/PasswordCrackerServer.csproj.CoreCompileInputs.cache new file mode 100644 index 0000000..4d07255 --- /dev/null +++ b/PasswordCrackerDistributed/PasswordCrackerServer/obj/Debug/PasswordCrackerServer.csproj.CoreCompileInputs.cache @@ -0,0 +1 @@ +f9778aa85649e535b2e2d42c3f99fd660304df99 diff --git a/PasswordCrackerDistributed/PasswordCrackerServer/obj/Debug/PasswordCrackerServer.csproj.FileListAbsolute.txt b/PasswordCrackerDistributed/PasswordCrackerServer/obj/Debug/PasswordCrackerServer.csproj.FileListAbsolute.txt index 2ce0519..b81056a 100644 --- a/PasswordCrackerDistributed/PasswordCrackerServer/obj/Debug/PasswordCrackerServer.csproj.FileListAbsolute.txt +++ b/PasswordCrackerDistributed/PasswordCrackerServer/obj/Debug/PasswordCrackerServer.csproj.FileListAbsolute.txt @@ -10,3 +10,10 @@ D:\Github\ItSecurityPasswordCracker\PasswordCrackerDistributed\PasswordCrackerSe D:\Github\ItSecurityPasswordCracker\PasswordCrackerDistributed\PasswordCrackerServer\bin\Debug\PasswordCrackerServer.exe D:\Github\ItSecurityPasswordCracker\PasswordCrackerDistributed\PasswordCrackerServer\bin\Debug\PasswordCrackerServer.pdb D:\Github\ItSecurityPasswordCracker\PasswordCrackerDistributed\PasswordCrackerServer\obj\Debug\PasswordCrackerServer.csprojResolveAssemblyReference.cache +C:\Users\Marcin\Documents\Visual Studio 2017\Projects\ItSecurityPasswordCracker\PasswordCrackerDistributed\PasswordCrackerServer\bin\Debug\PasswordCrackerServer.exe.config +C:\Users\Marcin\Documents\Visual Studio 2017\Projects\ItSecurityPasswordCracker\PasswordCrackerDistributed\PasswordCrackerServer\bin\Debug\PasswordCrackerServer.exe +C:\Users\Marcin\Documents\Visual Studio 2017\Projects\ItSecurityPasswordCracker\PasswordCrackerDistributed\PasswordCrackerServer\bin\Debug\PasswordCrackerServer.pdb +C:\Users\Marcin\Documents\Visual Studio 2017\Projects\ItSecurityPasswordCracker\PasswordCrackerDistributed\PasswordCrackerServer\obj\Debug\PasswordCrackerServer.csprojResolveAssemblyReference.cache +C:\Users\Marcin\Documents\Visual Studio 2017\Projects\ItSecurityPasswordCracker\PasswordCrackerDistributed\PasswordCrackerServer\obj\Debug\PasswordCrackerServer.csproj.CoreCompileInputs.cache +C:\Users\Marcin\Documents\Visual Studio 2017\Projects\ItSecurityPasswordCracker\PasswordCrackerDistributed\PasswordCrackerServer\obj\Debug\PasswordCrackerServer.exe +C:\Users\Marcin\Documents\Visual Studio 2017\Projects\ItSecurityPasswordCracker\PasswordCrackerDistributed\PasswordCrackerServer\obj\Debug\PasswordCrackerServer.pdb diff --git a/PasswordCrackerDistributed/PasswordCrackerServer/obj/Debug/PasswordCrackerServer.csprojResolveAssemblyReference.cache b/PasswordCrackerDistributed/PasswordCrackerServer/obj/Debug/PasswordCrackerServer.csprojResolveAssemblyReference.cache index fe0de23..fa8fb12 100644 Binary files a/PasswordCrackerDistributed/PasswordCrackerServer/obj/Debug/PasswordCrackerServer.csprojResolveAssemblyReference.cache and b/PasswordCrackerDistributed/PasswordCrackerServer/obj/Debug/PasswordCrackerServer.csprojResolveAssemblyReference.cache differ diff --git a/PasswordCrackerDistributed/PasswordCrackerServer/obj/Debug/PasswordCrackerServer.exe b/PasswordCrackerDistributed/PasswordCrackerServer/obj/Debug/PasswordCrackerServer.exe index 9a74985..477dd30 100644 Binary files a/PasswordCrackerDistributed/PasswordCrackerServer/obj/Debug/PasswordCrackerServer.exe and b/PasswordCrackerDistributed/PasswordCrackerServer/obj/Debug/PasswordCrackerServer.exe differ diff --git a/PasswordCrackerDistributed/PasswordCrackerServer/obj/Debug/PasswordCrackerServer.pdb b/PasswordCrackerDistributed/PasswordCrackerServer/obj/Debug/PasswordCrackerServer.pdb index 20c72ef..4ba808c 100644 Binary files a/PasswordCrackerDistributed/PasswordCrackerServer/obj/Debug/PasswordCrackerServer.pdb and b/PasswordCrackerDistributed/PasswordCrackerServer/obj/Debug/PasswordCrackerServer.pdb differ diff --git a/PasswordCrackerDistributed/PasswordCrackerServer/obj/Release/PasswordCrackerServer.csproj.CoreCompileInputs.cache b/PasswordCrackerDistributed/PasswordCrackerServer/obj/Release/PasswordCrackerServer.csproj.CoreCompileInputs.cache new file mode 100644 index 0000000..4d07255 --- /dev/null +++ b/PasswordCrackerDistributed/PasswordCrackerServer/obj/Release/PasswordCrackerServer.csproj.CoreCompileInputs.cache @@ -0,0 +1 @@ +f9778aa85649e535b2e2d42c3f99fd660304df99 -- cgit v1.2.3