Exemplo n.º 1
0
        public WaveletTreeNodeBin(BitArray text, NodeList leaves)
        {
            List<bool> distinctChars = new List<bool>();
              if (text.HasZeros())
            distinctChars.Add(false);
              if (text.HasOnes())
            distinctChars.Add(true);

              // Leaf Node
              if (distinctChars.Count == 1) {
            BitArray bitArray = new BitArray(text.Length);
            bitString = new BitString(bitArray);
            groupMembership = new Dictionary<bool, bool>();
            groupMembership[text[0]] = false;
            left = null;
            right = null;
            leaves.Add(text[0], this);
              }

              // Inner Node
              else {
            groupMembership = new Dictionary<bool, bool>(2);
            groupMembership[false] = false;
            groupMembership[true] = true;

            BitArray group1 = new BitArray(0);
            BitArray group2 = new BitArray(0);
            BitArray bitArray = new BitArray(text.Length);
            for (int i = 0; i < text.Length; i++) {
              if (text[i] == false) {
            group1 = group1.Append(false);
            bitArray[i] = false;
              }
              else {
            group2 = group2.Append(true);
            bitArray[i] = true;
              }
            }
            bitString = new BitString(bitArray);

            left = new WaveletTreeNodeBin(group1, leaves);
            right = new WaveletTreeNodeBin(group2, leaves);
            left.parent = right.parent = this;
              }
        }
Exemplo n.º 2
0
        /// <summary>
        ///     生成子密钥
        /// </summary>
        /// <param name="key">密钥</param>
        /// <returns></returns>
        private static BitArray[] GenerateKeys(BitArray key)
        {
            //置换选择1 64位->56位
            key = SwapSelect1(key);
            //Debug.WriteLine(key.PrintInBinary());

            BitArray[] output = new BitArray[16];

            BitArray c = new BitArray(28);
            BitArray d = new BitArray(28);
            c.SetRange(0, 28, key);
            d.SetRange(0, 28, key, 28);

            //Debug.WriteLine(c.PrintInBinary());
            //Debug.WriteLine(d.PrintInBinary());

            for (int i = 0; i < 16; i++)
            {
                //密钥产生
                //循环左移
                c = c.ROL(LeftShiftTime[i]);
                d = d.ROL(LeftShiftTime[i]);
                //Debug.WriteLine("i:{2} C:{0} D:{1}", c.PrintInBinary(), d.PrintInBinary(), i+1);
                //置换选择2
                output[i] = SwapSelect2(c.Append(d));
                //Debug.WriteLine(output[i].PrintInBinary());
                //Debug.WriteLine("C:{0} D:{1} out:{2}",c.PrintInHex(),d.PrintInHex(),output[i].PrintInHex());
            }
            return output;
        }