public ArmoryService(IReport rep)
 {
     report       = rep;
     inputService = new InputService();
     calc         = new ECCalc();
 }
Beispiel #2
0
        private unsafe bool LoopComp(string key, int missingCount, char missingChar, byte[] expectedHash)
        {
            int[]  missingIndexes = new int[missingCount];
            byte[] ba             = new byte[32];
            for (int i = 0, j = 0; i < ba.Length; i++)
            {
                int hi, lo;
                if (key[i * 2] == missingChar)
                {
                    hi = 0;
                    missingIndexes[j++] = i * 2;
                }
                else
                {
                    hi = key[i * 2] - 65;
                    hi = hi + 10 + ((hi >> 31) & 7);
                }
                if (key[i * 2 + 1] == '*')
                {
                    lo = 0;
                    missingIndexes[j++] = i * 2 + 1;
                }
                else
                {
                    lo = key[i * 2 + 1] - 65;
                    lo = lo + 10 + ((lo >> 31) & 7) & 0x0f;
                }

                ba[i] = (byte)(lo | hi << 4);
            }

            var    cartesian = CartesianProduct.Create(Enumerable.Repeat(Enumerable.Range(0, 16), missingCount));
            ECCalc calc      = new ECCalc();


            BigInteger         smallVal = new BigInteger(ba, true, true);
            EllipticCurvePoint smallPub = calc.MultiplyByG(smallVal);
            bool foundAny = false;

            Parallel.ForEach(cartesian, (item, loopState) =>
            {
                Span <byte> temp = new byte[32];

                int mis = 0;
                foreach (int keyItem in item)
                {
                    int misIndex = missingIndexes[mis];
                    if (misIndex % 2 == 0)
                    {
                        temp[misIndex / 2] |= (byte)(keyItem << 4);
                    }
                    else
                    {
                        temp[misIndex / 2] |= (byte)keyItem;
                    }
                    mis++;
                }

                BigInteger tempVal         = new BigInteger(temp, true, true);
                EllipticCurvePoint tempPub = calc.MultiplyByG(tempVal);
                EllipticCurvePoint pub     = calc.AddChecked(tempPub, smallPub);
                byte[] toHash = new byte[33];
                toHash[0]     = pub.Y.IsEven ? (byte)2 : (byte)3;
                byte[] xBytes = pub.X.ToByteArray(true, true);
                Buffer.BlockCopy(xBytes, 0, toHash, 33 - xBytes.Length, xBytes.Length);

                Hash160 hash = new Hash160();
                ReadOnlySpan <byte> actual = hash.ComputeHash(toHash);
                if (actual.SequenceEqual(expectedHash))
                {
                    char[] origHex = key.ToCharArray();
                    int index      = 0;
                    foreach (var keyItem in item)
                    {
                        origHex[missingIndexes[index++]] = GetHex(keyItem);
                    }
                    report.AddMessageSafe($"Found a key: {new string(origHex)}");
                    foundAny = true;
                    loopState.Break();
                }
            });

            if (!foundAny)
            {
                report.AddMessageSafe("Failed to find any key.");
            }
            return(foundAny);
        }
Beispiel #3
0
 public Bip32PathService(IReport rep)
 {
     report       = rep;
     inputService = new InputService();
     calc         = new ECCalc();
 }