Exemple #1
0
        private static byte[] EncryptSafe(byte[] bytes, int key)
        {
            Random rand = new Random(key);

            byte[] k = new byte[bytes.Length];
            rand.NextBytes(k);
            System.Collections.BitArray arr = new System.Collections.BitArray(bytes);
            arr.Xor(new System.Collections.BitArray(k));
            arr.CopyTo(k, 0);

            return(k);
        }
        private static byte[] Xor(byte[] a, byte[] b)
        {
            if (a.Length != b.Length)
            {
                throw new ArgumentException("Keys must be the same length for this mock implementation.");
            }

            var aBits = new System.Collections.BitArray(a);
            var bBits = new System.Collections.BitArray(b);

            var result = new byte[a.Length];

            aBits.Xor(bBits).CopyTo(result, 0);

            return(result);
        }
Exemple #3
0
        /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/

        /// <summary>Determine if this set intersects another.
        /// </summary>
        /// <param name="other">the other set in question.
        ///
        /// </param>
        public virtual bool intersects(terminal_set other)
        {
            not_null(other);

            /* make a copy of the other set */
            System.Collections.BitArray copy = (System.Collections.BitArray)other._elements.Clone();

            /* xor out our values */
            //UPGRADE_NOTE: In .NET BitArrays must be of the same size to allow the 'System.Collections.BitArray.Xor' operation. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1083"'
            copy = copy.Xor(this._elements);

            /* see if its different */
            //UPGRADE_TODO: method 'java.util.BitSet.equals' was converted to ' ' which has a different behavior. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1073_javautilBitSetequals_javalangObject"'
            return(!BitArraysEqual(copy, other._elements));
            // copy.Equals(other._elements);
        }
Exemple #4
0
        public void Xor_Test(int[] bits1, int[] bits2)
        {
            var size      = 12;
            var array1    = CreateArray(size);
            var array2    = CreateArray(size);
            var expected1 = new System.Collections.BitArray(size);
            var expected2 = new System.Collections.BitArray(size);

            foreach (var bit in bits1)
            {
                array1[bit] = expected1[bit] = true;
            }
            foreach (var bit in bits2)
            {
                array2[bit] = expected2[bit] = true;
            }

            var array    = array1.Xor(array2);
            var expected = expected1.Xor(expected2);

            CollectionAssert.AreEqual(array, expected);
            Assert.AreEqual(expected.Count, array.Count);
        }
Exemple #5
0
        static void Main(string[] args)
        {
            #region https://youtu.be/_UtKEYYhi24
            Coleccion show = new Coleccion();
            System.Collections.BitArray bitArray =
                new System.Collections.BitArray(
                    new byte[] { 1, 2, 4, 8, 16 });// Convertiendo byte a bit

            CountElement.Count(bitArray);
            Coleccion.Show(bitArray, 2);

            //// Obtenemos un bit en particular
            System.Console.WriteLine(bitArray.Get(3));

            //// ponemos un bit en particular
            bitArray.Set(3, true);
            System.Console.WriteLine(bitArray.Get(3));
            Coleccion.Show(bitArray, 2);


            //https://youtu.be/pGS78ttnqfY

            // Clonacion del BitArray
            System.Collections.BitArray bitArray2 =
                (System.Collections.BitArray)bitArray.Clone();

            //// Invertir el Array, NOT
            bitArray2.Not();
            Coleccion.Show(bitArray2, 2);

            // Creando otro Array
            System.Collections.BitArray bitArray3 =
                new System.Collections.BitArray(new byte[] { 5, 7, 9, 13, 15 });
            Coleccion.Show(bitArray3, 2, "3°Array");

            //// Hacemos Or entre Arreglos
            bitArray3.Or(bitArray); // El resultado se guarda en el Array que llevo
                                    //acabo la invocacion.
            Coleccion.Show(bitArray, pNombre: "1°Array");
            Coleccion.Show(bitArray3, 3, pNombre: "Result");
            System.Console.WriteLine("=|||||||||=");

            //// Hacemos AND entre Array
            Coleccion.Show(bitArray, pNombre: "1°Array");
            Coleccion.Show(bitArray3, pNombre: "3°Array");

            // Hacemos el AND, BitArray 3 se modifica con el resultado
            bitArray3.And(bitArray);
            Coleccion.Show(bitArray3, 3, "Result");
            System.Console.WriteLine("=&&&&&&&&&&&=");

            //// Hamos XOR entre Array
            bitArray3 =
                new System.Collections.BitArray(new byte[] { 5, 7, 9, 13, 21 });
            Coleccion.Show(bitArray, pNombre: "1°Array");
            Coleccion.Show(bitArray3, pNombre: "3°Array");

            // Hacemos el XOR, Array 3 se modifica con el resultado
            bitArray3.Xor(bitArray);
            Coleccion.Show(bitArray3, pNombre: "Result");

            System.Console.ReadKey();
            #endregion
        }