예제 #1
0
        public static bool[] Solve(uint[][] tables, int inByte0, int inByte1, int inByte2, int inByte3, int outByte, int outBit)
        {
            uint[] key    = new uint[4];
            Random random = new Random();
            List <RandomGaussRow> list           = new List <RandomGaussRow>();
            RandomGaussRow        randomGaussRow = new RandomGaussRow();

            randomGaussRow.SetA(0);
            randomGaussRow.SetB();
            list.Add(randomGaussRow);
            byte[] array = new byte[16];
            for (int i = 1; i < 1024; i++)
            {
                RandomGaussRow randomGaussRow2;
                do
                {
                    random.NextBytes(array);
                    byte[] array2 = GTA5Crypto.DecryptRoundA(array, key, tables);
                    randomGaussRow2 = new RandomGaussRow();
                    randomGaussRow2.SetA((int)array2[inByte0]);
                    randomGaussRow2.SetA(256 + (int)array2[inByte1]);
                    randomGaussRow2.SetA(512 + (int)array2[inByte2]);
                    randomGaussRow2.SetA(768 + (int)array2[inByte3]);
                    if (((int)array[outByte] & 1 << outBit) != 0)
                    {
                        randomGaussRow2.SetB();
                    }
                    if (i == 767)
                    {
                        randomGaussRow2 = new RandomGaussRow();
                        randomGaussRow2.SetA(767);
                        randomGaussRow2.SetB();
                    }
                    if (i == 1023)
                    {
                        randomGaussRow2 = new RandomGaussRow();
                        randomGaussRow2.SetA(1023);
                        randomGaussRow2.SetB();
                    }
                    for (int j = 0; j < i; j++)
                    {
                        if (randomGaussRow2.GetA(j))
                        {
                            randomGaussRow2 ^= list[j];
                        }
                    }
                }while (!randomGaussRow2.GetA(i));
                list.Add(randomGaussRow2);
            }
            bool[] array3 = new bool[1024];
            for (int k = 1023; k >= 0; k--)
            {
                bool b = list[k].GetB();
                array3[k] = b;
                for (int l = 0; l < k; l++)
                {
                    if (list[l].GetA(k))
                    {
                        list[l].B ^= b;
                    }
                }
            }
            return(array3);
        }
예제 #2
0
        public static bool[] Solve(
            uint[][] tables,
            int inByte0, int inByte1, int inByte2, int inByte3,
            int outByte, int outBit)
        {
            var noKey  = new uint[] { 0, 0, 0, 0 };
            var random = new Random();

            var pivots = new List <RandomGaussRow>();

            var firstPivot = new RandomGaussRow();

            firstPivot.SetA(0);
            firstPivot.SetB();
            pivots.Add(firstPivot);

            var buf_encrypted = new byte[16];

            for (int pivotIdx = 1; pivotIdx < 1024; pivotIdx++)
            {
                while (true)
                {
                    random.NextBytes(buf_encrypted);

                    // decrypt
                    var buf_decrypted = GTA5Crypto.DecryptRoundA(
                        buf_encrypted,
                        noKey,
                        tables);

                    // make row
                    var row = new RandomGaussRow();
                    //row.A[0 + buf_decrypted[inByte0]] = true;
                    //row.A[256 + buf_decrypted[inByte1]] = true;
                    //row.A[512 + buf_decrypted[inByte2]] = true;
                    //row.A[768 + buf_decrypted[inByte3]] = true;
                    //row.B = (buf_encrypted[outByte] & (1 << outBit)) != 0;
                    row.SetA(0 + buf_decrypted[inByte0]);
                    row.SetA(256 + buf_decrypted[inByte1]);
                    row.SetA(512 + buf_decrypted[inByte2]);
                    row.SetA(768 + buf_decrypted[inByte3]);
                    if ((buf_encrypted[outByte] & (1 << outBit)) != 0)
                    {
                        row.SetB();
                    }

                    if (pivotIdx == 0x2ff)
                    {
                        row = new RandomGaussRow();
                        row.SetA(0x2ff);
                        row.SetB();
                    }
                    if (pivotIdx == 0x3ff)
                    {
                        row = new RandomGaussRow();
                        row.SetA(0x3ff);
                        row.SetB();
                    }

                    // apply pivotIdx-1 pivots
                    for (int k = 0; k < pivotIdx; k++)
                    {
                        if (row.GetA(k))
                        {
                            row ^= pivots[k];
                            //var ppp = pivots[k];
                            //for (int p = 0; p < 1024; p++)
                            //    row.A[p] ^= ppp.A[p];
                            //row.B ^= ppp.B;
                        }
                    }

                    // check if this row is a new pivot
                    if (row.GetA(pivotIdx))
                    {
                        pivots.Add(row);
                        //    Console.WriteLine("Found pivot for column " + pivotIdx.ToString());
                        break;
                    }
                }
            }

            var result = new bool[1024];

            for (int j = 1023; j >= 0; j--)
            {
                bool val = pivots[j].GetB();
                result[j] = val;
                for (int k = 0; k < j; k++)
                {
                    if (pivots[k].GetA(j))
                    {
                        pivots[k].B ^= val;
                    }
                }
            }

            return(result);
        }