aboutsummaryrefslogtreecommitdiff
blob: 18031984fe7fc9f73bd163c7e9c5487e4996a83a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Sockets;
using DistributedPasswordCracker.Client.Models;

namespace DistributedPasswordCracker.Client
{
    class Program
    {
        const int NumberOfTasks = 5;

        private static StreamReader sr;
        private static StreamWriter sw;

        static void Main(string[] args)
        {
            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 < 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++)
                    chunk[j] = splitDictionary[i, j];
                result = DecryptPassword(chunk);
            }
            if (result.Count != 0)
            {
                sw.WriteLine(result[0].ToString());
            }
            else
            {
                sw.WriteLine("Nothing Found!");
            }
        }

        private static string GetData()
        {
            string data = "";

            while (true)
            {
                string message = sr.ReadLine();
                if (message != "") data += message + "\n";
                else break;
            }

            return data;
        }

        private static string ParseData(string data)
        {
            var splitData = data.Split('\n');

            if (splitData[0] == "DPCP 1.0")
            {
                splitData[1] = splitData[1].Replace('|', '\n');
                File.WriteAllText("passwords.txt", splitData[1]);
                File.WriteAllText("dictionary.txt", splitData[2]);
            }

            return splitData[2];
        }

        private static string[,] SplitDictionary(string dictionary)
        {
            string[] dicWords = dictionary.Split('|');
            int dicWordsLength = dicWords.Length;
            string[,] splitDictionary = new string[NumberOfTasks,dicWordsLength/NumberOfTasks];
            int offset = 0;
            int j = 0;

            for (int i = 0; i < NumberOfTasks; i++)
            {
                while (j < dicWordsLength/NumberOfTasks)
                {
                    splitDictionary[i, j] = dicWords[j + offset];
                    j++;
                }
                offset += dicWordsLength/NumberOfTasks;
                j = 0;
            }

            return splitDictionary;
        }

        private static List<UserInfoClearText> DecryptPassword(string[] dictionary)
        {
            Cracking cracker = new Cracking();
            var result = cracker.RunCracking(dictionary);

            return result;
}
    }
}