public double AddWatermarkSubstring(string key_bit, string hmac_sub, int key_idx, int lut_idx)
        {
            Dictionary <string, string> original_tt = new Dictionary <string, string>(TruthTable);
            Dictionary <string, string> tt_sec      = new Dictionary <string, string>();

            // is the truth table implemented in minterms or maxterms?
            string min_maxterm = "1";

            // reverse keybit
            string incorrect_keybit = key_bit == "1" ? "0" : "1";

            foreach (KeyValuePair <string, string> tt_line in original_tt)
            {
                if (tt_line.Value == "0")
                {
                    min_maxterm = "0";
                }
            }

            while (TruthTable.Count > 0)
            {
                string tt_entry = TruthTable.Keys.ElementAt <string>(0);
                string tt_value = TruthTable[tt_entry];
                TruthTable.Remove(tt_entry);

                tt_entry = tt_entry.Insert(lut_idx, key_bit);
                tt_sec.Add(tt_entry, tt_value);
            }

            // insert the HMAC, baby!
            for (int i = 0; i < hmac_sub.Length; i++)
            {
                string tt_line = Convert.ToString(i, 2).PadLeft(NumInputs, '0');

                tt_line = tt_line.Insert(lut_idx, incorrect_keybit);

                // maintain a min/maxterm representation
                if (hmac_sub[i].ToString() == min_maxterm)
                {
                    tt_sec.Add(tt_line, min_maxterm);
                }
            }


            TruthTable = tt_sec;
            LUTinputs.Insert(lut_idx, "sk[" + key_idx + "]");
            this.NumInputs++;
            //return HammingDistance(lut_idx);
            return(0);
        }
        public void AddKeyInput(string key_bit, int key_idx, int lut_idx)
        {
            keyIndex = lut_idx;
            keyVal   = key_bit;
            Random rand = new Random();
            Dictionary <string, string> tt_sec = new Dictionary <string, string>();

            IsMinimized = false;
            //string tt_value = "";
            //string original_tt_val = expandTruthTable();
            Dictionary <string, string> original_tt = new Dictionary <string, string>(TruthTable);
            string tmp = "1";

            foreach (KeyValuePair <string, string> kvp in TruthTable)
            {
                if (kvp.Value == "0")
                {
                    tmp = "0";
                }
            }
            while (TruthTable.Count > 0)
            {
                string tt_entry = TruthTable.Keys.ElementAt <string>(0);
                string tt_value = TruthTable[tt_entry];
                TruthTable.Remove(tt_entry);

                tt_entry = tt_entry.Insert(key_idx, key_bit);
                tt_sec.Add(tt_entry, tt_value);
            }

            NumInputs++;
            ContentSize *= 2;



            ////fill in don't care logic
            for (int i = 0; i < NumInputs - 2; i++)
            {
                StringBuilder tt_entry = new StringBuilder("0".PadLeft(NumInputs, '0'));

                string tt_value = tmp;

                if (key_bit.Equals("1"))
                {
                    tt_entry[key_idx] = '0';
                }
                else
                {
                    tt_entry[key_idx] = '1';
                }
                while (!tt_sec.ContainsKey(tt_entry.ToString()))
                {
                    for (int j = 0; j < NumInputs; j++)
                    {
                        if (j == key_idx)
                        {
                            continue;
                        }
                        if (rand.Next(100) < 20)
                        {
                            tt_entry[j] = '1';                      // we should use a template (of n input function) instead of random gen. this is just for test.
                        }
                        else
                        {
                            tt_entry[j] = '-';
                        }
                    }
                    if (tt_entry.ToString().Contains('1'))
                    {
                        try
                        {
                            tt_sec.Add(tt_entry.ToString(), tt_value);
                        }
                        catch { }
                    }
                }
            }



            LUTinputs.Insert(key_idx, "sk[" + lut_idx + "]");
            TruthTable = tt_sec;
            string new_tt = expandTruthTable();

            secured = true;
            var newer_tt = expandTruthTable();

            keyBits++;
            //hammingDistance = HammingDistance(key_idx);
        }