Пример #1
0
        public unsafe void ProcessPermutations(PhraseSet initialPhraseSet, Word[] allWords, int[] wordIndexes, ulong[] permutations, uint[] expectedHashesVector, Action <byte[], uint> action)
        {
            fixed(uint *bufferPointer = this.Buffer, initialBufferPointer = initialPhraseSet.Buffer)
            {
                fixed(ulong *permutationsPointer = permutations)
                {
                    fixed(int *wordIndexesPointer = wordIndexes)
                    {
                        fixed(Word *allWordsPointer = allWords)
                        {
                            fixed(uint *expectedHashesPointer = expectedHashesVector)
                            {
                                for (var i = 0; i < permutations.Length; i += Constants.PhrasesPerSet)
                                {
                                    MD5Unmanaged.FillPhraseSet(
                                        (ulong *)initialBufferPointer,
                                        (ulong *)bufferPointer,
                                        (ulong *)allWordsPointer,
                                        wordIndexesPointer,
                                        permutationsPointer + i,
                                        wordIndexes.Length);

                                    MD5Unmanaged.ComputeMD5(bufferPointer, expectedHashesPointer);

                                    if (bufferPointer[Constants.PhrasesPerSet / 2] != 0xFFFFFFFF)
                                    {
                                        for (var j = 0; j < Constants.PhrasesPerSet; j++)
                                        {
                                            // 16 matches are packed in 8 32-bit numbers: [0,1], [8,9], [2,3], [10,11], [4, 5], [12, 13], [6, 7], [14, 15]
                                            var position = ((j / 2) % 4) * 2 + (j / 8);
                                            var match    = (bufferPointer[position] >> (4 * (j % 2))) & 0xF0F0F0F;
                                            if (match != 0)
                                            {
                                                var bufferInfo = ((ulong)bufferPointer[Constants.PhrasesPerSet] << 32) | bufferPointer[j];
                                                MD5Unmanaged.FillPhraseSet(
                                                    (ulong *)initialBufferPointer,
                                                    (ulong *)bufferPointer,
                                                    (ulong *)allWordsPointer,
                                                    wordIndexesPointer,
                                                    permutationsPointer + i,
                                                    wordIndexes.Length);
                                                action(this.GetBytes(j), match);
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #2
0
        private void ProcessSum(int[] sum, uint[] expectedHashesVector, Action <byte[], uint> action)
        {
            var initialPhraseSet = new PhraseSet();

            initialPhraseSet.Init();
            initialPhraseSet.FillLength(this.NumberOfCharacters, sum.Length);
            var phraseSet = new PhraseSet();

            phraseSet.Init();
            var permutationsFilter = ComputeFilter(sum);
            var wordsVariants      = this.ConvertVectorsToWordIndexes(sum);

            foreach (var wordsArray in Flattener.Flatten(wordsVariants))
            {
                phraseSet.ProcessPermutations(
                    initialPhraseSet,
                    this.AllWords,
                    wordsArray,
                    PrecomputedPermutationsGenerator.HamiltonianPermutations(wordsArray.Length, permutationsFilter),
                    expectedHashesVector,
                    action);
            }
        }