Beispiel #1
0
        public void TestTransform()
        {
            var trits      = Converter.TrytesToTrits("ADHMOICIPKGYHYL9VMLSSXHGKTUTEQUTIWUQWSVYHZWTAHNIYQICEJWFTCYBGRGRM9DWBCGDELIGEIIIH");
            var ulongTrits = UlongTritConverter.TritsToUlong(trits, Curl.StateLength, Mode._64bit);

            ulongTrits.Low[0] = 15811494920322472813;
            ulongTrits.Low[1] = 17941353825114769379;
            ulongTrits.Low[2] = 576458557575118879;
            ulongTrits.Low[3] = 18446741876833779711;

            ulongTrits.High[0] = 13176245766935394011;
            ulongTrits.High[1] = 14403622084951293727;
            ulongTrits.High[2] = 18445620372817592319;
            ulongTrits.High[3] = 2199023255551;

            var curl = new NonceCurl(ulongTrits.Low, ulongTrits.High, (int)CurlMode.CurlP27);

            curl.Transform();

            for (var i = 0; i < this.expectedAfterTransform.Length; i++)
            {
                Assert.AreEqual(this.expectedAfterTransform[i].Item1, curl.Low[i]);
                Assert.AreEqual(this.expectedAfterTransform[i].Item2, curl.High[i]);
            }
        }
        public int[] Search(int[] trits, int security, int length, int offset)
        {
            var ulongTrits = this.PrepareTrits(trits, offset);
            var curl       = new NonceCurl(ulongTrits.Low, ulongTrits.High, this.Rounds);
            var size       = Math.Min(length, AbstractCurl.HashLength) - offset;

            var index = 0;

            while (index == 0)
            {
                var incrementResult = curl.Increment(offset + size * 2 / 3, offset + size);
                size = Math.Min(Pascal.RoundThird(offset + size * 2 / 3 + incrementResult), AbstractCurl.HashLength) - offset;

                var curlCopy = curl.Clone();
                curlCopy.Transform();

                index = Check(security, curlCopy.Low.Take(AbstractCurl.HashLength).ToArray(), curlCopy.High.Take(AbstractCurl.HashLength).ToArray());
            }

            var result = new TrinaryDemultiplexer(new UlongTritTouple(curl.Low.Take(size).ToArray(), curl.High.Take(size).ToArray()));

            return(result.Get(index));
        }