public static PDF From(FormattedFile file) { return(PDF.deserialize(file.serialize())); }
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); }