Example #1
0
        private PDF verificationRequest(FormattedFile file, string key)
        {
            // TODO: Connect to JEE
            Message messageToSend = new Message("verificationFile", "0.1", new string[] { file.serialize() });



            // Mock the response
            PDF pdf = new PDF();

            pdf.path        = file.path;
            pdf.filename    = file.filename;
            pdf.content     = file.content;
            pdf.validity    = false;
            pdf.pourcentage = 24.5;
            pdf.tested      = 200;
            pdf.recognized  = 49;
            Message mockedResponse = new Message("verificationFile", "0.1", new string[] { pdf.serialize() });


            PDF receivedFile = PDF.deserialize((string)mockedResponse.data[0]);

            receivedFile.key = key;
            if (receivedFile.validity)
            {
                return(receivedFile);
            }

            return(null);
        }
Example #2
0
 public Decryption(object[] data)
 {
     foreach (string strFile in data)
     {
         FormattedFile file = FormattedFile.deserialize(strFile);
         this.files.Add(file);
     }
 }
Example #3
0
        private FormattedFile decryptTask(FormattedFile file, string newKey)
        {
            string decryptedContent = this.decryptContent(file.content, newKey);

            // Create a copy so we send variations of the original file.
            FormattedFile clonedFile = (FormattedFile)file.Clone();

            clonedFile.content = decryptedContent;
            return(clonedFile);
        }
Example #4
0
 public static PDF From(FormattedFile file)
 {
     return(PDF.deserialize(file.serialize()));
 }
Example #5
0
        private PDF decryptFile(FormattedFile file)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();

            key = new int[4] {
                beginning - 1, beginning, beginning, beginning
            };
            int nbMaxKeys = (int)Math.Pow((limit - beginning) + 1, key.Length);

            var runningTasks = new CountdownEvent(1);
            int keysUsed     = 0;

            // Use ParallelOptions instance to limit to processor
            ParallelOptions po = new ParallelOptions();

            po.MaxDegreeOfParallelism = Environment.ProcessorCount;

            PDF    fileToReturn = null;
            object returnLock   = new object();

            indexListKeys = 0;

            List <string> keys = new List <string>();

            Parallel.For(0, nbMaxKeys, po, (index, loop) =>
            {
                int[] keyArray;
                lock (this.key)
                {
                    keyArray = this.keyAvailable();
                    //if (keysUsed % 676 == 1) Debug.WriteLine("[SERVICE] current keys used = " + keysUsed);
                }

                string newKey = "";
                foreach (int i in keyArray)
                {
                    newKey += Convert.ToChar(i);
                }

                FormattedFile fileToVerify = this.decryptTask(file, newKey);
                Interlocked.Increment(ref keysUsed);

                PDF resultVerification = this.verificationRequest(fileToVerify, newKey);

                // TODO: Treat the verification response
                if (resultVerification != null)
                {
                    loop.Stop();
                    //sendEmail(newKey, resultVerification.filename);
                    lock (returnLock)
                    {
                        fileToReturn = resultVerification;
                    }
                }
            });


            Debug.WriteLine("[SERVICE] Decryption - decryptFile: keysUsed = " + keysUsed);
            Debug.WriteLine("[SERVICE] Decryption - decryptFile: time = " + sw.ElapsedMilliseconds / 1000 + "." + sw.ElapsedMilliseconds % 1000 + " sec");
            return(fileToReturn);
        }