diff options
author | marcinzelent <zelent.marcin@gmail.com> | 2018-03-17 00:37:41 -0700 |
---|---|---|
committer | marcinzelent <zelent.marcin@gmail.com> | 2018-03-17 00:37:41 -0700 |
commit | 017da9023af14430adc165b524ee50ae37ba9f5e (patch) | |
tree | cf330d55becbb1c777bef571e55962f1ac71542f | |
parent | c684015a82de139e53b60a4805d18137b74c13ac (diff) |
Changes
17 files changed, 95 insertions, 139 deletions
diff --git a/.vs/ItSecurityPasswordCracker/v15/.suo b/.vs/ItSecurityPasswordCracker/v15/.suo Binary files differnew file mode 100644 index 0000000..f666f62 --- /dev/null +++ b/.vs/ItSecurityPasswordCracker/v15/.suo diff --git a/.vs/VSWorkspaceState.json b/.vs/VSWorkspaceState.json new file mode 100644 index 0000000..853ccc6 --- /dev/null +++ b/.vs/VSWorkspaceState.json @@ -0,0 +1,10 @@ +{ + "ExpandedNodes": [ + "", + "\\PassCrackerClient", + "\\PasswordCrackerDistributed", + "\\PasswordCrackerDistributed\\PasswordCrackerServer" + ], + "SelectedNode": "\\PasswordCrackerDistributed\\PasswordCrackerDistributed.sln", + "PreviewInSolutionExplorer": false +}
\ No newline at end of file diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite Binary files differnew file mode 100644 index 0000000..3e0da68 --- /dev/null +++ b/.vs/slnx.sqlite diff --git a/PassCrackerClient/PassCrackerClient/Program.cs b/PassCrackerClient/PassCrackerClient/Program.cs index be3b6b4..45f0309 100755 --- a/PassCrackerClient/PassCrackerClient/Program.cs +++ b/PassCrackerClient/PassCrackerClient/Program.cs @@ -2,32 +2,43 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; using System.Net.Sockets; -using System.Text; -using System.Threading.Tasks; namespace PassCrackerClient { class Program { + const int NumberOfTasks = 5; + private static StreamReader sr; private static StreamWriter sw; + static void Main(string[] args) { - TcpClient clientSocket = new TcpClient("192.168.3.163", 6789); + Console.Write("Connecting to server... "); + TcpClient clientSocket = new TcpClient("127.0.0.1", 6789); NetworkStream ns = clientSocket.GetStream(); + Console.Write("OK\n"); sr = new StreamReader(ns); sw = new StreamWriter(ns); sw.AutoFlush = true; + Console.Write("Getting data from the server... "); string data = GetData(); + if (data != "") Console.Write("OK\n"); + + Console.Write("Parsing data... "); string dictionary = ParseData(data); + if (dictionary != "") Console.Write("OK\n"); + + Console.Write("Splitting dictionary... "); string[,] splitDictionary = SplitDictionary(dictionary); + if (splitDictionary[0,0] != "") Console.Write("OK\n"); List<UserInfoClearText> result = new List<UserInfoClearText>(); - for(int i = 0; i < 5; i++) + for(int i = 0; i < NumberOfTasks; i++) { + Console.Write("Running task no." + (i + 1) + "...\n" ); int rowLength = splitDictionary.GetLength(1); string[] chunk = new string[rowLength]; for (int j = 0; j < rowLength; j++) @@ -76,18 +87,18 @@ namespace PassCrackerClient { string[] dicWords = dictionary.Split('|'); int dicWordsLength = dicWords.Length; - string[,] splitDictionary = new string[5,dicWordsLength/5]; + string[,] splitDictionary = new string[NumberOfTasks,dicWordsLength/NumberOfTasks]; int offset = 0; int j = 0; - for (int i = 0; i < 5; i++) + for (int i = 0; i < NumberOfTasks; i++) { - while (j < dicWordsLength/5) + while (j < dicWordsLength/NumberOfTasks) { splitDictionary[i, j] = dicWords[j + offset]; j++; } - offset += dicWordsLength/5; + offset += dicWordsLength/NumberOfTasks; j = 0; } diff --git a/PasswordCrackerDistributed/.vs/PasswordCrackerDistributed/v15/.suo b/PasswordCrackerDistributed/.vs/PasswordCrackerDistributed/v15/.suo Binary files differnew file mode 100644 index 0000000..cb3b2d3 --- /dev/null +++ b/PasswordCrackerDistributed/.vs/PasswordCrackerDistributed/v15/.suo 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 --- /dev/null +++ b/PasswordCrackerDistributed/.vs/PasswordCrackerDistributed/v15/Server/sqlite3/db.lock diff --git a/PasswordCrackerDistributed/.vs/PasswordCrackerDistributed/v15/Server/sqlite3/storage.ide b/PasswordCrackerDistributed/.vs/PasswordCrackerDistributed/v15/Server/sqlite3/storage.ide Binary files differnew file mode 100644 index 0000000..8081bae --- /dev/null +++ b/PasswordCrackerDistributed/.vs/PasswordCrackerDistributed/v15/Server/sqlite3/storage.ide 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<UserInfo> userInfos = PasswordFileHandler.ReadPasswordFile("passwords.txt");
List<clientConnection> clients = new List<clientConnection>();
- List<string> allchunks;
+ List<string> allChunks = new List<string>();
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<string>()
- {
- 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<string> words = new List<string>();
-
- 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<string> chunk1 = new List<string>(words.GetRange(0, 65000));
- string chunk1String = "";
- foreach (string s1 in chunk1)
- {
- chunk1String += s1 + "|";
- }
- List<string> chunk2 = new List<string>(words.GetRange(65000, 65000));
- string chunk2String = "";
- foreach (string s2 in chunk2)
- {
- chunk2String += s2 + "|";
- }
- List<string> chunk3 = new List<string>(words.GetRange(130000, 65000));
- string chunk3String = "";
- foreach (string s3 in chunk3)
- {
- chunk3String += s3 + "|";
- }
- List<string> chunk4 = new List<string>(words.GetRange(195000, 65000));
- string chunk4String = "";
- foreach (string s4 in chunk4)
- {
- chunk4String += s4 + "|";
- }
- List<string> chunk5 = new List<string>(words.GetRange(260000, 51141));
- string chunk5String = "" + " ";
- foreach (string s5 in chunk5)
- {
- chunk5String += s5 + "|";
- }
- allchunks = new List<string>()
- {
- 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<string[]> RunAsync(List<clientConnection> 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<string[]> RunAsync(List<clientConnection> clients)
+ {
+ List<Task<string>> tasks = new List<Task<string>>();
+ 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 Binary files differindex 9a74985..477dd30 100644 --- a/PasswordCrackerDistributed/PasswordCrackerServer/bin/Debug/PasswordCrackerServer.exe +++ b/PasswordCrackerDistributed/PasswordCrackerServer/bin/Debug/PasswordCrackerServer.exe diff --git a/PasswordCrackerDistributed/PasswordCrackerServer/bin/Debug/PasswordCrackerServer.pdb b/PasswordCrackerDistributed/PasswordCrackerServer/bin/Debug/PasswordCrackerServer.pdb Binary files differindex 20c72ef..4ba808c 100644 --- a/PasswordCrackerDistributed/PasswordCrackerServer/bin/Debug/PasswordCrackerServer.pdb +++ b/PasswordCrackerDistributed/PasswordCrackerServer/bin/Debug/PasswordCrackerServer.pdb 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<string> Doit()
+ public async Task<string> 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 Binary files differindex fe0de23..fa8fb12 100644 --- a/PasswordCrackerDistributed/PasswordCrackerServer/obj/Debug/PasswordCrackerServer.csprojResolveAssemblyReference.cache +++ b/PasswordCrackerDistributed/PasswordCrackerServer/obj/Debug/PasswordCrackerServer.csprojResolveAssemblyReference.cache diff --git a/PasswordCrackerDistributed/PasswordCrackerServer/obj/Debug/PasswordCrackerServer.exe b/PasswordCrackerDistributed/PasswordCrackerServer/obj/Debug/PasswordCrackerServer.exe Binary files differindex 9a74985..477dd30 100644 --- a/PasswordCrackerDistributed/PasswordCrackerServer/obj/Debug/PasswordCrackerServer.exe +++ b/PasswordCrackerDistributed/PasswordCrackerServer/obj/Debug/PasswordCrackerServer.exe diff --git a/PasswordCrackerDistributed/PasswordCrackerServer/obj/Debug/PasswordCrackerServer.pdb b/PasswordCrackerDistributed/PasswordCrackerServer/obj/Debug/PasswordCrackerServer.pdb Binary files differindex 20c72ef..4ba808c 100644 --- a/PasswordCrackerDistributed/PasswordCrackerServer/obj/Debug/PasswordCrackerServer.pdb +++ b/PasswordCrackerDistributed/PasswordCrackerServer/obj/Debug/PasswordCrackerServer.pdb 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 |