当前位置: 首页>>代码示例>>C#>>正文


C# BitArray.Xor方法代码示例

本文整理汇总了C#中System.Collections.BitArray.Xor方法的典型用法代码示例。如果您正苦于以下问题:C# BitArray.Xor方法的具体用法?C# BitArray.Xor怎么用?C# BitArray.Xor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Collections.BitArray的用法示例。


在下文中一共展示了BitArray.Xor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

 static void Main(string[] args)
 {
     var bits = new BitArray(2);
     bits[1] = true;
     bits.Xor(bits); // Bitwise exclusive-OR bits with itself
     Console.WriteLine(bits[1]); // False
 }
开发者ID:PhilTheAir,项目名称:CSharp,代码行数:7,代码来源:BitArrayContainer.cs

示例2: Xor

		public static byte[] Xor(byte[] value1, byte[] value2) {
			var array1 = new BitArray(value1);
			var array2 = new BitArray(value2);
			var result = array1.Xor(array2);
			byte[] b = new byte[result.Count / 8];
			result.CopyTo(b, 0);
			return b;
		}
开发者ID:Helen1987,项目名称:edu,代码行数:8,代码来源:Xor.cs

示例3: Clean

        public static BitArray Clean(BitArray depthMap, int depthWidth, byte[] video, int videoWidth)
        {
            BitArray orig = new BitArray(depthMap);

            // find the border: grow, extract the difference, grow again.
            const int growthSize = 2;
            var grownMap = Dilate(depthMap, depthWidth, growthSize);
            var border = Dilate(depthMap.Xor(grownMap), depthWidth, growthSize + 1);

            // get a more accurate picture by filtering by video
            var filteredBorder = FilterByVideo(border, depthWidth, video, videoWidth);
            var enhancedMap = (filteredBorder == null) ? orig : border.Not().Or(filteredBorder).And(grownMap);
            return RemoveNoise(enhancedMap, depthWidth);
        }
开发者ID:smanoharan,项目名称:314Kinect,代码行数:14,代码来源:HandImageCleaner.cs

示例4: DecryptionCBC

 void DecryptionCBC()
 {
     var key = Encoding.GetEncoding(1251).GetBytes(Key.ToString().PadLeft(8, '0'));
     GenerationKey(new BitArray(key));
     AddTempBit(BitArrayET);
     BitArrayDT = new BitArray(BitArrayET.Length);
     BitArray C = new BitArray(PSCh());
     for (var i = 0; i < BitArrayET.Length; i += 64)
     {
         var aBitEncrypt = GetValue(BitArrayET, i, i + 64);
         var aBitDecryption = base.Decryption(new BitArray(aBitEncrypt));
         var M = C.Xor(aBitDecryption);
         C = aBitEncrypt;
         Concat(BitArrayDT, M, i);
     }
 }
开发者ID:nanoboot,项目名称:LAB_InfSec,代码行数:16,代码来源:Modes.cs

示例5: XOR

        /// <summary>
        /// Xors the 2 component.
        /// </summary>
        /// <param name="compA">Component.</param>
        /// <param name="compB">Component.</param>
        /// <returns>Xor result as string</returns>
        public string XOR(string compA, string compB = null)
        {
            if (compB == null)
            {
                compB = ReverseString(compA);
            }

            var barA = new BitArray(HexToByte(compA));
            var barB = new BitArray(HexToByte(compB));
            var barC = new BitArray(compA.Length);
            barC = barB.Xor(barA);
            var byteC = new byte[barC.Length / 8];
            barC.CopyTo(byteC, 0);

            return ByteToHex(byteC);
        }
开发者ID:serdarb,项目名称:Membership-Service,代码行数:22,代码来源:CryptographyHelper.cs

示例6: XOR

        private Valor XOR(Valor llave1, Valor llave2)
        {
            byte[] llaveArray1 = ASCIIEncoding.ASCII.GetBytes(llave1.ToString());
            byte[] llaveArray2 = ASCIIEncoding.ASCII.GetBytes(llave2.ToString());

            BitArray bitArray1 = new BitArray(llaveArray1);
            BitArray bitArray2 = new BitArray(llaveArray2);

            BitArray bitArrayResultado=bitArray1.Xor(bitArray2);

            byte[] llaveArrayResultado = ToByteArray(bitArrayResultado);

            string resultado = Convert.ToBase64String(llaveArrayResultado, 0, llaveArrayResultado.Length);

            return new Caracter(resultado);
        }
开发者ID:jmptrader,项目名称:Switch-Transaccional,代码行数:16,代码来源:Operacion.cs

示例7: BitArrayDemo

        static void BitArrayDemo()
        {
            var bits1 = new BitArray(8);
            bits1.SetAll(true);
            bits1.Set(1, false);
            bits1[5] = false;
            bits1[7] = false;
            Console.Write("initialized: ");
            DisplayBits(bits1);
            Console.WriteLine();

            DisplayBits(bits1);
            bits1.Not();
            Console.Write(" not ");
            DisplayBits(bits1);
            Console.WriteLine();

            var bits2 = new BitArray(bits1);
            bits2[0] = true;
            bits2[1] = false;
            bits2[4] = true;
            DisplayBits(bits1);
            Console.Write(" or ");
            DisplayBits(bits2);
            Console.Write(" : ");
            bits1.Or(bits2);
            DisplayBits(bits1);
            Console.WriteLine();

            DisplayBits(bits2);
            Console.Write(" and ");
            DisplayBits(bits1);
            Console.Write(" : ");
            bits2.And(bits1);
            DisplayBits(bits2);
            Console.WriteLine();

            DisplayBits(bits1);
            Console.Write(" xor ");
            DisplayBits(bits2);
            bits1.Xor(bits2);
            Console.Write(" : ");
            DisplayBits(bits1);
            Console.WriteLine();
        }
开发者ID:CSharpDev,项目名称:Csharp,代码行数:45,代码来源:Program.cs

示例8: CodeSegments

        public CodedPiece CodeSegments()
        {
            List<int> pieceBuilders = new List<int>() { firstSegment.SegmentNumber };
            BitArray xoredBits = new BitArray(firstSegment.Data);

            foreach (FileSegment segment in segments.Skip(1))
            {
                var currentBits = new BitArray(segment.Data);
                xoredBits = xoredBits.Xor(currentBits);
                pieceBuilders.Add(segment.SegmentNumber);
            }

            return new CodedPiece()
            {
                BasedOnSegments = pieceBuilders,
                CodedWord = xoredBits
            };
        }
开发者ID:trobinpl,项目名称:csharpLTCode,代码行数:18,代码来源:Coder.cs

示例9: BitwiseXOR

        /// <summary>
        /// Bitwise XOR for 2 Bytes.
        /// </summary>
        /// <param name="t1">Left side for comparison</param>
        /// <param name="t2">Right side for comparison</param>
        /// <returns>Resulting byte</returns>
        static internal byte BitwiseXOR(byte t1, byte t2)
        {
            BitArray baLft = null;
            BitArray baRght = null;
            BitArray baXor = null;

            //Have to use Byte Arrays as the constructor for the BitArray, otherwise the 
            //integer value of the current byte is used to set the length of the bitArray instead of the value.
            byte[] bytL = new byte[1];
            byte[] bytR = new byte[1];

            bytL[0] = t1;
            bytR[0] = t2;
            baLft = new BitArray(bytL);
            baRght = new BitArray(bytR);
            baXor = baLft.Xor(baRght);

            byte[] ba2BytArr = new byte[8];

            baXor.CopyTo(ba2BytArr, 0);

            return ba2BytArr[0];
        }
开发者ID:vebin,项目名称:soa,代码行数:29,代码来源:Utils.cs

示例10: GenerateOneRound

        /// <summary>
        /// Generate one xor round. 
        /// </summary>
        /// <param name="to">Where to put the result</param>
        /// <param name="key">Key used</param>
        /// <param name="counter">Shifter of the key</param>
        private void GenerateOneRound(ref BitArray to, BitArray key, int counter)
        {
            this.ExtendToSizeLeft(ref this.KeyExtended, key, to.Length, counter);
            to = to.Xor(this.KeyExtended);


        }
开发者ID:Frosne,项目名称:SShA,代码行数:13,代码来源:Program.cs

示例11: F

 BitArray F(BitArray aBite, BitArray Key)
 {
     ExtensionE(ref aBite);
     aBite.Xor(Key);
     BitArray tempBitArray = new BitArray(32);
     var iBlock = 1;
     var iTempBitsBlock = 0;
     for (var i = 0; i < aBite.Length; i += 6)
     {
         SetBits(ref tempBitArray, GammirovaniyeS(GetValue(aBite, i, i + 6), iBlock++), iTempBitsBlock);
         iTempBitsBlock += 4;
     }
     aBite = Permutation(tempBitArray, P);
     return aBite;
 }
开发者ID:nanoboot,项目名称:LAB_InfSec,代码行数:15,代码来源:Algorithm.cs

示例12: PrefixesEquals

        private bool PrefixesEquals(CidrRange other)
        {
            var leftMask = new BitArray(Prefix);
            var leftSuffix = new BitArray(32, false);
            for (int i = 31; i >= 32 - Suffix; i--)
            {
                leftSuffix[i] = true;
            }
            leftMask = leftSuffix.And(leftMask);

            var rightMask = new BitArray(other.Prefix);
            var rightSuffix = new BitArray(32, false);
            for (int i = 31; i >= 32 - other.Suffix; i--)
            {
                rightSuffix[i] = true;
            }
            rightMask = rightSuffix.And(rightMask);

            var result = rightMask.Xor(leftMask);
            return result.Cast<bool>().ToArray().Skip(32 - Math.Min(Suffix, other.Suffix)).All(x => !x);
        }
开发者ID:siniypin,项目名称:katas,代码行数:21,代码来源:CidrRange.cs

示例13: Encode

        /// <summary>
        /// Шифруем строку, используя двоичные данные ключа. Данные ключа должны быть длиннее чем сообщение
        /// </summary>
        /// <param name="message"></param>
        /// <param name="keyData"></param>
        /// <returns></returns>
        public static String Encode(String message, byte[] keyData)
        {
            // Проверяем длину данных ключа
            if (message.Length > keyData.Length)
                throw new ArgumentException("Insufficient Key Data");

            // Используем кодировку ASCII, чтобы получить массив байтов из строки сообщения
            byte[] msgBytes = Encoding.ASCII.GetBytes(message);
            byte[] trimData = new byte[msgBytes.Length];

            // Оба битовых  массива должны быть одной длины, копируем необходимое количество байт из массива ключевых данных
            Array.Copy(keyData, trimData, trimData.Length);

            // Создаем массив битов из данных сообщения и ключевых данных
            BitArray msg = new BitArray(msgBytes);
            BitArray key = new BitArray(trimData);

            // Выполняем операцию XOR на двух массивах
            BitArray output = msg.Xor(key);

            // Копирует массив вывода в массив сообщения
            output.CopyTo(msgBytes, 0);

            // Используем кодировку base-64 чтобы преобразовать двоичные данные в печатаемую строку
            return Convert.ToBase64String(msgBytes);
        }
开发者ID:jedemdasseine,项目名称:CellularAutomata,代码行数:32,代码来源:Cell.cs

示例14: feistelFunction

 private BitArray feistelFunction(BitArray keyBits, BitArray Bittext_16)
 {
     BitArray afterParity = Bittext_16;
     if (checkParity(keyBits)) //true if parity is even
     {
         afterParity = Bittext_16.Not();
         //Console.WriteLine("Right after negating : " + BitOperations.getBinaryString(afterParity));
     }
     //Console.WriteLine("Keybits for xoring : " + BitOperations.getBinaryString(keyBits));
     var feistelOutput = keyBits.Xor(new BitArray(afterParity));
     //Console.WriteLine("right 16 bits after fiestal function : " + BitOperations.getBinaryString(a));
     return feistelOutput;
 }
开发者ID:AravindSreenivasa,项目名称:AppliedCryptography,代码行数:13,代码来源:decryption.cs

示例15: RenameLetters

        string RenameLetters(string originalName)
        {
            BitArray arr = new BitArray(md5.ComputeHash(Encoding.UTF8.GetBytes(originalName)));

            Random rand = new Random(originalName.GetHashCode() * seed);
            byte[] xorB = new byte[arr.Length / 8];
            rand.NextBytes(xorB);
            BitArray xor = new BitArray(xorB);

            BitArray result = arr.Xor(xor);
            byte[] buff = new byte[result.Length / 8];
            result.CopyTo(buff, 0);

            StringBuilder ret = new StringBuilder();
            int m = 0;
            for (int i = 0; i < buff.Length; i++)
            {
                m = (m << 8) + buff[i];
                while (m > 52)
                {
                    int n = m % 26;
                    if (n < 26)
                        ret.Append((char)('A' + n));
                    else
                        ret.Append((char)('a' + (n - 26)));
                    m /= 52;
                }
            }
            return ret.ToString();
        }
开发者ID:n017,项目名称:Confuser,代码行数:30,代码来源:ObfuscationHelper.cs


注:本文中的System.Collections.BitArray.Xor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。