コード例 #1
0
ファイル: MfKeyTest.cs プロジェクト: kgamecarter/Crapto1Sharp
        public void MfKey32_SameNtTwoNonce(uint uid, uint nt, uint nr0, uint nr1, ulong expectedKey)
        {
            var p64     = Crypto1.PrngSuccessor(nt, 64);
            var crypto1 = new Crypto1(expectedKey);

            crypto1.Crypto1Word(uid ^ nt);
            nr0 ^= crypto1.Crypto1Word(nr0);
            var ar0 = p64 ^ crypto1.Crypto1Word();

            crypto1 = new Crypto1(expectedKey);
            crypto1.Crypto1Word(uid ^ nt);
            nr1 ^= crypto1.Crypto1Word(nr1);
            var ar1 = p64 ^ crypto1.Crypto1Word();

            var key = MfKey.MfKey32(uid, nt, nr0, ar0, nr1, ar1);

            Assert.AreEqual(expectedKey, key);
        }
コード例 #2
0
        private static string KeyWorker(List <MyKey> keys)
        {
            var results = keys
                          .GroupBy(k => new { k.UID, k.Sector, k.Block, k.KeyType })
                          .AsParallel()
                          .AsOrdered()
                          .Select(group =>
            {
                var list = group.Select(k => new Nonce()
                {
                    Nt = k.nt0,
                    Nr = k.nr0,
                    Ar = k.ar0
                }).ToList();

                if (list.Count < 2)
                {
                    return(null);
                }

                var keyType = (group.Key.KeyType == 0x60) ? "A" : "B";
                Debug.WriteLine($"{group.Key.Sector} - {keyType} | {list.Count}");

                var key = MfKey.MfKey32(group.Key.UID, list);
                if (key != ulong.MaxValue)
                {
                    foreach (var item in group)
                    {
                        item.Found = true;
                        item.key   = key;
                    }
                    var s = $"[S{group.Key.Sector} / B{group.Key.Block}] Key{keyType} [{key:x12}]";
                    Debug.WriteLine(s);
                    return(s);
                }
                return(null);
            })
                          .Where(r => r != null)
                          .ToList();

            results.Add(string.Empty);
            return(string.Join(Environment.NewLine, results));
        }
コード例 #3
0
        private void selftest()
        {
            // MOEBIUS test
            //   <uid>      <nt>       <nr_0>     <ar_0>     <nt1>      <nr_1>    <ar_1>
            // 0x12345678 0x1AD8DF2B 0x1D316024 0x620EF048 0x30D6CB07 0xC52077E2 0x837AC61A
            //  Found Key: [a0a1a2a3a4a5]

            var t = new MyKey
            {
                UID = 0x12345678,
                nt0 = 0x1AD8DF2B,
                nr0 = 0x1D316024,
                ar0 = 0x620EF048,
                nt1 = 0x30D6CB07,
                nr1 = 0xC52077E2,
                ar1 = 0x837AC61A
            };

            t.key   = MfKey.MfKey32(t.UID, t.nt0, t.nr0, t.ar0, t.nt1, t.nr1, t.ar1);
            t.Found = t.key != ulong.MaxValue;
            if (t.Found && t.key == 0xa0a1a2a3a4a5)
            {
                var s = $"[S{t.Sector}/B%d] Type {t.KeyType} Key found [{t.key:x12}] {Environment.NewLine} ";
                Debug.WriteLine(s);
            }

            // MFKEY32 standard
            //::        < uid >    < nt >     < nr_0 >   < ar_0 >   < nr_1 >   < ar_1 >
            //         0x52B0F519 0x5417D1F8 0x4D545EA7 0xE15AC8C2 0xDAC1A7F4 0x5AE5C37F
            //t.UID = 0x52B0F519;
            //t.nt0 = 0x5417D1F8; t.nr0 = 0x4D545EA7; t.ar0 = 0xE15AC8C2;
            //                    t.nr1 = 0xDAC1A7F4; t.ar1 = 0x5AE5C37F;

            //t.Found = mfkey32(t.UID, t.nt0, t.nr0, t.ar0, t.nr1, t.ar1, out t.key);
            //if (t.Found)
            //{
            //    var s = $"[S{t.Sector}/B%d] Type {t.KeyType} Key found [{t.key:x12}] {Environment.NewLine} ";
            //    Debug.WriteLine(s);
            //}
        }
コード例 #4
0
ファイル: MfKeyTest.cs プロジェクト: kgamecarter/Crapto1Sharp
        public void MfKey32_SameNtManyNonce(uint uid, uint nt, int randomSeed, int nonceCount, ulong expectedKey)
        {
            var    p64  = Crypto1.PrngSuccessor(nt, 64);
            var    list = new List <Nonce>();
            Random rnd  = new Random(randomSeed);

            for (int i = 0; i < nonceCount; i++)
            {
                var crypto1 = new Crypto1(expectedKey);
                crypto1.Crypto1Word(uid ^ nt);
                var nr = (uint)rnd.Next();
                list.Add(new Nonce()
                {
                    Nr = crypto1.Crypto1Word(nr) ^ nr,
                    Ar = p64 ^ crypto1.Crypto1Word()
                });
            }

            var key = MfKey.MfKey32(uid, nt, list);

            Assert.AreEqual(expectedKey, key);
        }