コード例 #1
0
        private void btnStructure_Click(object sender, EventArgs e)
        {
            int DATASIZE = (int)numBits.Value;
            //string rawData = "000073af00000000";
            string rawData = "000000b5";
            //string rawData = "73af73af73af73af73af73af73af73af73af73af73af73af73af73af73af73af73af73af73af73af73af73af73af73af73af73af73af73af73af73af73af73af73af73af73af73af73af73af73af73af73af73af73af73af";
            uint[] aa = new uint[(DATASIZE / 16 > 0) ? DATASIZE / 16 : 1];
            uint[] bb = new uint[(DATASIZE / 16 > 0) ? DATASIZE / 16 : 1];
            BitHolder32[] a = new BitHolder32[(DATASIZE / 16 > 0) ? DATASIZE / 16 : 1];
            XORCollector32Bit[] b = new XORCollector32Bit[(DATASIZE / 16 > 0) ? DATASIZE / 16 : 1];
            for (int i = 0; i < ((DATASIZE / 16 > 0) ? DATASIZE / 16 : 1); i++)
            {
                a[i] = new BitHolder32(i * 32);
                b[i] = new XORCollector32Bit();
                aa[i] = uint.Parse(rawData.Substring(i * 8, 8), System.Globalization.NumberStyles.HexNumber);
            }

            SortedDictionary<ANDCombination, object>[] xorEq = new SortedDictionary<ANDCombination, object>[DATASIZE * 2];
            for (int i = 0; i < xorEq.Length; i++)
            {
                xorEq[i] = new SortedDictionary<ANDCombination, object>();
            }

            for (int i = 0; i < DATASIZE; i++)
            {
                for (int j = 0; j < DATASIZE; j++)
                {
                    bb[(i + j) / 32] ^= (((aa[i / 32] >> (i % 32)) & (aa[j / 32 + DATASIZE / 32] >> (j + DATASIZE % 32)) & 1) << ((i + j) % 32));
                    ANDCombination andc = new ANDCombination(i + 1, j + DATASIZE + 1);
                    xorEq[(i + j)][andc] = null;
                    //if (!TestPartialEncryption(aa, bb, xorEq))
                    //    throw new Exception("You messed up!");
                }
            }

            StringBuilder sb = new StringBuilder();
            AppendStructure(sb, xorEq);

            sb.AppendLine();
            sb.AppendLine();
            bb.AppendHex(sb);
            sb.AppendLine();

            tbOut.Text = sb.ToString();
        }
コード例 #2
0
        /// <summary>
        /// It doesn't matter how many XOR_0's you have because y ^ 0 = y;
        /// We need to track XOR_1's because y ^ 1 = !y  && y ^ 1 ^ 1 = y;
        /// </summary>
        /// <param name="x"></param>
        public void XOR(BitHolder32 x)
        {
            for (int i = 0; i < 32; i++)
            {
                int ele0 = x.AndOperations[i][0];  // we need to check ele0 before we sort the data
                int ele1 = x.AndOperations[i][1];  // we need to verify consistant data
                if (ele0 == -2)
                {
                    if (ele1 != -2)  // I've programmed in some sort of logic error if this is the case.
                    {
                        throw new Exception("Unexpected Data");
                    }
                    xor1state[i] = !xor1state[i];
                    throw new Exception("Unexpected Data");
                }
                else if (ele0 == -1)
                {
                    // do nothing in this case because A ^ 0 == A
                }
                else if (ele1 == -1) // ele0 should have been set to 0 (-1) also because A & 0 == 0
                {                    // this is definately a logic error on my part.
                    throw new Exception("Unexpected Data");
                }
                else if (ele1 == -2)  // this case is fine because ele0 & 1 == ele0
                {
                    var t = new ANDCombination(ele0, ele1);
                    if (!xorOperations[i].Remove(t))    // if it existed in the xor chain list then remove it
                    {                                   // because (A ^ A ^ B) => (0 ^ B) => (B)
                        xorOperations[i].Add(t, null);  // if it wasn't in the xor chain list then we add it
                    }
                    throw new Exception("Unexpected Logic Path"); // I don't believe I ever set my data to look like this.
                    // it should come in the form A & A, not A & 1.
                }
                else // both ele0 and ele1 must not be a set value of 0 or 1 (-1 or -2) now and refer to bitIDs
                {
                    var t = new ANDCombination(ele0, ele1);

                    // if it existed in the xor chain list then remove it
                    // because (A ^ A ^ B == 0 ^ B) => (B ^ 0 == B)
                    if (!xorOperations[i].Remove(t))
                    {   // if it wasn't in the xor chain list then we add it
                        xorOperations[i].Add(t, null);
                    }
                }
            }
        }