Ejemplo n.º 1
0
        public void addElement(String s)
        {
            //word=binascii.a2b_qp(qgram) # convert to binary

            String mykey = "zuxujesw";

            byte[] keyBytes = Encoding.UTF8.GetBytes(mykey);
            String hex1     = "";
            String hex2     = "";

            try {
                HMACSHA1 mac = new HMACSHA1(keyBytes);
                mac.Initialize();
                byte[] inputBytes = new byte[s.Length];
                for (var i = 0; i < s.Length; i++)
                {
                    inputBytes.SetValue(Convert.ToByte(s[i]), i);//Encoding.UTF8.GetBytes(s);
                }
                byte[] digest = mac.TransformFinalBlock(inputBytes, 0, inputBytes.Length);
                hex1 = BitConverter.ToString(digest).Replace("-", string.Empty);
            } catch (Exception ex) {
                Console.Error.WriteLine("HMACSHA1: Hash error: " + ex.Message);
            }
            try {
                HMACMD5 mac = new HMACMD5(keyBytes);
                mac.Initialize();
                byte[] inputBytes = Encoding.UTF8.GetBytes(s);
                byte[] digest     = mac.TransformFinalBlock(inputBytes, 0, inputBytes.Length);
                hex2 = BitConverter.ToString(digest).Replace("-", string.Empty);
            } catch (Exception ex) {
                Console.Error.WriteLine("HMACMD5: Hash error: " + ex.Message);
            }
            // convert hash key to integer
            BigInteger h1 = BigInteger.Parse(hex1, NumberStyles.AllowHexSpecifier);
            BigInteger h2 = BigInteger.Parse(hex2, NumberStyles.AllowHexSpecifier);

            for (int i = 0; i < k; i++)
            {
                BigInteger bigi = new BigInteger(i);
                //BigInteger res = h2.multiply(bigi).add(h1).mod(new BigInteger(this.bitSetSize + ""));
                BigInteger res      = (h2 * bigi + h1) % new BigInteger(this.bitSetSize);
                int        position = (int)res;
                if (!bitset.get(position))
                {
                    bitsSet++;
                }
                if (bitset.get(position))
                {
                    if (cols[position] == 0)
                    {
                        cols[position] = 1;
                    }
                    else
                    {
                        cols[position] = cols[position] + 1;
                    }
                }
                bitset.set(position);
            }
            numberOfAddedElements++;
        }