Changeset 296


Ignore:
Timestamp:
Apr 23, 2009, 10:14:50 PM (13 years ago)
Author:
Sören Rinne
Message:
  • added BoolComparator, compares two boolean inputs
  • added setting in TextOutput to display boolean values as numeric values (true/false vs. 1/0)
Location:
trunk/CrypPlugins
Files:
12 added
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypPlugins/ANDBinary/ANDBinary.cs

    r292 r296  
    226226
    227227        private ANDBinarySettings settings;
    228         private bool inputOne = true;
    229         private bool inputTwo = true;
     228        private bool inputOne = false;
     229        private bool inputTwo = false;
    230230        private bool output;
    231231
     
    308308        public void Initialize()
    309309        {
    310             // should inputs be dirty or clean at the beginning?
    311             // set both inputs clean
    312             inputOneFlag = 1;
    313             inputTwoFlag = 1;
     310            // set input flags according to settings
     311            if (settings.FlagInputOne) inputOneFlag = 1;
     312            else inputOneFlag = -1;
     313            if (settings.FlagInputTwo) inputTwoFlag = 1;
     314            else inputTwoFlag = -1;
    314315        }
    315316
     
    378379        public void Execute()
    379380        {
    380             if (inputOneFlag == 1)
    381             {
    382                 if (inputTwoFlag == 1)
    383                 {
    384                     // flag all inputs as dirty
    385                     inputOneFlag = -1;
    386                     inputTwoFlag = -1;
    387 
    388                     output = inputOne & inputTwo;
    389                     OnPropertyChanged("Output");
    390                 }
     381            if (inputOneFlag == 1 && inputTwoFlag == 1)
     382            {               
     383                // flag all inputs as dirty
     384                inputOneFlag = -1;
     385                inputTwoFlag = -1;
     386
     387                output = inputOne & inputTwo;
     388                OnPropertyChanged("Output");
    391389            }
    392390        }
  • trunk/CrypPlugins/ANDBinary/ANDBinarySettings.cs

    r292 r296  
    240240        }
    241241
     242        bool flagInputOne;
     243        [ContextMenu("Declare Flag I1 clean", " yes / no ", 0, DisplayLevel.Beginner, ContextMenuControlType.CheckBox, null, "Set Flag of Input One to clean at the beginning of the chain.")]
     244        [TaskPaneAttribute("Declare Flag I1 clean", " yes / no ", "", 0, false, DisplayLevel.Beginner, ControlType.CheckBox, null)]
     245        public bool FlagInputOne
     246        {
     247            get { return this.flagInputOne; }
     248            set
     249            {
     250                this.flagInputOne = value;
     251                OnPropertyChanged("FlagInputOne");
     252                HasChanges = true;
     253            }
     254
     255        }
     256
     257        bool flagInputTwo;
     258        [ContextMenu("Declare Flag I2 clean", " yes / no ", 0, DisplayLevel.Beginner, ContextMenuControlType.CheckBox, null, "Set Flag of Input Two to clean at the beginning of the chain.")]
     259        [TaskPaneAttribute("Declare Flag I2 clean", " yes / no ", "", 0, false, DisplayLevel.Beginner, ControlType.CheckBox, null)]
     260        public bool FlagInputTwo
     261        {
     262            get { return this.flagInputTwo; }
     263            set
     264            {
     265                this.flagInputTwo = value;
     266                OnPropertyChanged("FlagInputTwo");
     267                HasChanges = true;
     268            }
     269
     270        }
     271
    242272        #endregion
    243273
  • trunk/CrypPlugins/LFSR/LFSR.cs

    r292 r296  
    5252        public String tapSequencebuffer = "1";
    5353        public Char outputbuffer = '0';
     54        public bool lastInputPropertyClock = false;
    5455
    5556        #endregion
     
    8384                inputTapSequence = value;
    8485                OnPropertyChanged("InputTapSequence");
     86                lastInputPropertyClock = false;
    8587            }
    8688        }
     
    9698                inputSeed = value;
    9799                OnPropertyChanged("InputSeed");
    98             }
    99         }
    100 
     100                lastInputPropertyClock = false;
     101            }
     102        }
     103        /*
    101104        [PropertyInfo(Direction.Input, "Clock", "Optional clock input. LFSR only advances if clock is 1.", "", false, false, DisplayLevel.Beginner, QuickWatchFormat.Hex, null)]
    102105        public CryptoolStream InputClock
     
    121124                OnPropertyChanged("InputClock");
    122125            }
    123         }
     126        }*/
    124127
    125128        [PropertyInfo(Direction.Input, "Clock", "Optional clock input. LFSR only advances if clock is true.", "", false, false, DisplayLevel.Beginner, QuickWatchFormat.Text, null)]
     
    133136                inputClockBool = value;
    134137                OnPropertyChanged("InputClockBool");
    135             }
    136         }
    137 
    138         [PropertyInfo(Direction.Output, "Output stream", "LFSR Output Stream", "", true, false, DisplayLevel.Beginner, QuickWatchFormat.Hex, null)]
     138                lastInputPropertyClock = true;
     139            }
     140        }
     141
     142        [PropertyInfo(Direction.Output, "Output stream", "LFSR Stream Output. Use this fpr bulk output.", "", false, false, DisplayLevel.Beginner, QuickWatchFormat.Hex, null)]
    139143        public CryptoolStream OutputStream
    140144        {
     
    160164        }
    161165
    162         [PropertyInfo(Direction.Output, "Boolean Output", "Boolean Output.", "", true, false, DisplayLevel.Beginner, QuickWatchFormat.Text, null)]
     166        [PropertyInfo(Direction.Output, "Boolean Output", "LFSR Boolean Output. Use this output together with a clock input.", "", false, false, DisplayLevel.Beginner, QuickWatchFormat.Text, null)]
    163167        public bool OutputBool
    164168        {
     
    171175        }
    172176
    173         [PropertyInfo(Direction.Output, "Clocking Bit Output", "Clocking Bit Output.", "", true, false, DisplayLevel.Beginner, QuickWatchFormat.Text, null)]
     177        [PropertyInfo(Direction.Output, "Clocking Bit Output", "Clocking Bit Output.", "", false, false, DisplayLevel.Beginner, QuickWatchFormat.Text, null)]
    174178        public bool OutputClockingBit
    175179        {
     
    323327
    324328        // Function to turn around tapSequence (01101 -> 10110)
    325         private char[] TurnAround(char[] tapSequence)
     329        private char[] ReverseOrder(char[] tapSequence)
    326330        {
    327331            //String tempString = new String(tapSequence);
     
    342346        }
    343347
     348        private string BuildPolynomialFromBinary(char [] tapSequence)
     349        {
     350            string polynomial = "Feedback polynomial: \n";
     351            char[] tempTapSequence = ReverseOrder(tapSequence);
     352            int power;
     353
     354            //build polynomial
     355            for (int i = 0; i < tapSequence.Length; i++)
     356            {
     357                power = (i - tapSequence.Length + 1) * -1 % tapSequence.Length;
     358                if (tempTapSequence[i] == '1')
     359                {
     360                    if (power == 1) polynomial += "x + ";
     361                    else if (power != 0) polynomial += "x^" + power + " + ";
     362                    else polynomial += "1";
     363                }
     364            }
     365
     366            return  polynomial;
     367        }
     368
    344369        #endregion
    345370
     
    352377        private void processLFSR()
    353378        {
     379            // check if event was from the boolean clock input
     380            // if so, check if boolean clock should be used
     381            // if not, do not process LFSR
     382            if (lastInputPropertyClock)
     383            {
     384                if (!settings.UseBoolClock) return;
     385            }
    354386            // process LFSR
    355387           
     
    432464
    433465                // convert tapSequence into char array
    434                 char[] tapSequenceCharArray = TurnAround(tapSequencebuffer.ToCharArray());
     466                char[] tapSequenceCharArray = ReverseOrder(tapSequencebuffer.ToCharArray());
    435467
    436468                if (tapSequencebuffer.Length != inputSeed.Length)
     
    509541
    510542                // check if Rounds are given
    511                 int defaultRounds = 4;
     543                int defaultRounds = 1;
    512544                int actualRounds;
    513545
     
    584616
    585617                        //update quickwatch presentation
    586                         lFSRPresentation.FillBoxes(seedCharArray, tapSequenceCharArray, outputBit);
     618                        lFSRPresentation.FillBoxes(seedCharArray, tapSequenceCharArray, outputBit, BuildPolynomialFromBinary(tapSequenceCharArray));
    587619
    588620                        // write current "seed" back to seedbuffer
     
    614646
    615647                            //update quickwatch presentation
    616                             lFSRPresentation.FillBoxes(seedCharArray, tapSequenceCharArray, seedCharArray[seedBits - 1]);
     648                            lFSRPresentation.FillBoxes(seedCharArray, tapSequenceCharArray, seedCharArray[seedBits - 1], BuildPolynomialFromBinary(tapSequenceCharArray));
    617649                            /////////
    618650                        }
     
    620652                        {
    621653                            // update quickwatch with current state but without any output bit
    622                             lFSRPresentation.FillBoxes(seedCharArray, tapSequenceCharArray, ' ');
     654                            lFSRPresentation.FillBoxes(seedCharArray, tapSequenceCharArray, ' ', BuildPolynomialFromBinary(tapSequenceCharArray));
    623655                        }
    624656
  • trunk/CrypPlugins/LFSR/LFSRPresentation.xaml.cs

    r292 r296  
    279279        }
    280280
    281         public void FillBoxes(char[] state, char[] tapSequence, char output)
     281        public void FillBoxes(char[] state, char[] tapSequence, char output, string polynomial)
    282282        {
    283283            // fill the boxes with current state
     
    287287                Visual childVisual;
    288288                int i;
    289                 string polynomial = "Feedback polynomial: \n";
     289               
    290290                for (i = 0; i < state.Length; i++)
    291291                {
     
    300300                        myInfoText.Background = Brushes.DodgerBlue;
    301301                    }*/
    302 
    303                     //build polynomial
    304                     int power;
    305                     power = (i - state.Length + 1) * -1 % state.Length;
    306                     if (tapSequence[i] == '1')
    307                     {
    308                         if (power == 1) polynomial += "x + ";
    309                         else if (power != 0) polynomial += "x^" + power + " + ";
    310                         else polynomial += "1";
    311                     }
    312302                }
    313303
  • trunk/CrypPlugins/LFSR/LFSRSettings.cs

    r292 r296  
    2222        private bool hasChanges = false;
    2323       
    24         private int rounds = 4; //how many bits will be generated
     24        private int rounds = 1; //how many bits will be generated
    2525        //[ContextMenu("Rounds", "How many bits shall be generated?", 1, DisplayLevel.Beginner, ContextMenuControlType.ComboBox, new int[] { 10, 50, 100 }, "10 bits", "50 bits", "100 bits")]
    2626        //[TaskPane("Rounds", "How many bits shall be generated?", null, 1, false, DisplayLevel.Beginner, ControlType.TextBox)]
    27         [TaskPane("Rounds", "How many bits shall be generated? Note: This only applies if no boolean clock is used.", null, 0, false, DisplayLevel.Beginner, ControlType.NumericUpDown, ValidationType.RangeInteger, 0, int.MaxValue)]
     27        [TaskPane("Number of rounds", "How many bits shall be generated? Note: This only applies if no boolean clock is used.", null, 2, false, DisplayLevel.Beginner, ControlType.NumericUpDown, ValidationType.RangeInteger, 0, int.MaxValue)]
    2828        public int Rounds
    2929        {
     
    3737
    3838        private int clockingBit = 0;
    39         [TaskPane("Clocking Bit", "Which bit shall be generated as an additional output? For example as an clocking bit.", null, 0, false, DisplayLevel.Beginner, ControlType.NumericUpDown, ValidationType.RangeInteger, 0, int.MaxValue)]
     39        [TaskPane("Clocking bit number", "Which bit shall be generated as an additional output? For example as an clocking bit.", "Additional Output Bit", 0, false, DisplayLevel.Beginner, ControlType.NumericUpDown, ValidationType.RangeInteger, 0, int.MaxValue)]
    4040        public int ClockingBit
    4141        {
     
    5050
    5151        private bool useClockingBit = false;
    52         [ContextMenu("Use ClockingBit", "With this checkbox enabled, the clocking bit will be generated.", 0, DisplayLevel.Experienced, ContextMenuControlType.CheckBox, null, new string[] { "Use clocking bit?" })]
    53         [TaskPane("Use ClockingBit", "With this checkbox enabled, clocking bit will be generated.", null, 1, false, DisplayLevel.Beginner, ControlType.CheckBox, "", null)]
     52        [ContextMenu("Use clocking bit", "With this checkbox enabled, the clocking bit will be generated.", 0, DisplayLevel.Experienced, ContextMenuControlType.CheckBox, null, new string[] { "Use clocking bit?" })]
     53        [TaskPane("Use clocking bit", "With this checkbox enabled, clocking bit will be generated.", "Additional Output Bit", 1, false, DisplayLevel.Beginner, ControlType.CheckBox, "", null)]
    5454        public bool UseClockingBit
    5555        {
     
    6565        private bool useBoolClock = false;
    6666        [ContextMenu("Use BoolClock", "With this checkbox enabled, BoolClock will be used.", 0, DisplayLevel.Experienced, ContextMenuControlType.CheckBox, null, new string[] { "Use Boolean clock?" })]
    67         [TaskPane("Use BoolClock", "With this checkbox enabled, BoolClock will be used.", null, 1, false, DisplayLevel.Beginner, ControlType.CheckBox, "", null)]
     67        [TaskPane("Use BoolClock", "With this checkbox enabled, BoolClock will be used.", "Clock Properties", 0, false, DisplayLevel.Beginner, ControlType.CheckBox, "", null)]
    6868        public bool UseBoolClock
    6969        {
     
    7878
    7979        private bool alwaysCreateOutput = false;
    80         [ContextMenu("Always create output", "With this checkbox enabled, an output will be generated, even though the clock is set to false. The output bit will be the bit from the last clock cycle.", 0, DisplayLevel.Experienced, ContextMenuControlType.CheckBox, null, new string[] { "Always generate output?" })]
    81         [TaskPane("Always create output", "With this checkbox enabled, an output will be generated, even though the clock is set to false. The output bit will be the bit from the last clock cycle.", null, 1, false, DisplayLevel.Beginner, ControlType.CheckBox, "", null)]
     80        [ContextMenu("Always create output", "With this checkbox enabled, an output will be generated, even though the clock is set to false. The output bit will be the bit from the last clock cycle.", 1, DisplayLevel.Experienced, ContextMenuControlType.CheckBox, null, new string[] { "Always generate output?" })]
     81        [TaskPane("Always create output", "With this checkbox enabled, an output will be generated, even though the clock is set to false. The output bit will be the bit from the last clock cycle.", "Clock Properties", 1, false, DisplayLevel.Beginner, ControlType.CheckBox, "", null)]
    8282        public bool AlwaysCreateOutput
    8383        {
  • trunk/CrypPlugins/Majority/Majority.cs

    r292 r296  
    394394        public void Execute()
    395395        {
    396             if (inputOneFlag == 1)
    397             {
    398                 if (inputTwoFlag == 1)
    399                 {
    400                     if (inputThreeFlag == 1)
    401                     {
    402 
    403                         // flag all inputs as dirty
    404                         inputOneFlag = -1;
    405                         inputTwoFlag = -1;
    406                         inputThreeFlag = -1;
    407 
    408                         // generate output
    409                         int cntZeros = 0;
    410                         int cntOnes = 1;
    411                         if (inputOne) cntOnes++; else cntZeros++;
    412                         if (inputTwo) cntOnes++; else cntZeros++;
    413                         if (inputThree) cntOnes++; else cntZeros++;
    414                         if (cntOnes >= cntZeros) output = true; else output = false;
    415                         OnPropertyChanged("Output");
    416                     }
    417                 }
     396            if (inputOneFlag == 1 && inputTwoFlag == 1 && inputThreeFlag == 1)
     397            {
     398                // flag all inputs as dirty
     399                inputOneFlag = -1;
     400                inputTwoFlag = -1;
     401                inputThreeFlag = -1;
     402
     403                // generate output
     404                int cntZeros = 0;
     405                int cntOnes = 0;
     406                if (inputOne) cntOnes++; else cntZeros++;
     407                if (inputTwo) cntOnes++; else cntZeros++;
     408                if (inputThree) cntOnes++; else cntZeros++;
     409                if (cntOnes >= cntZeros) output = true; else output = false;
     410                OnPropertyChanged("Output");
    418411            }
    419412        }
  • trunk/CrypPlugins/TextOutput/TextOutput.cs

    r232 r296  
    410410        else if (value is bool)
    411411        {
    412           fillValue = ((bool)value).ToString();
     412            if (settings.BooleanAsNumeric)
     413            {
     414                fillValue = Convert.ToInt32(value).ToString();
     415            }
     416            else
     417            {
     418                fillValue = ((bool)value).ToString();
     419            }
    413420        }
    414421        else if (value is CryptoolStream)
  • trunk/CrypPlugins/TextOutput/TextOutputSettings.cs

    r224 r296  
    333333        {
    334334          append = value;
     335          hasChanges = true;
    335336          OnPropertyChanged("Append");
    336337        }
     
    394395    }
    395396
     397    private bool booleanAsNumeric = false;
     398    [ContextMenu("Display boolean as numeric value", "With this checkbox enabled, incoming boolean values will be displayed as numeric values (1/0 instead of True/False).", 5, DisplayLevel.Experienced, ContextMenuControlType.CheckBox, null, new string[] { "Display boolean as numeric value" })]
     399    [TaskPane("Display boolean as numeric value", "With this checkbox enabled, incoming boolean values will be displayed as numeric values (1/0 instead of True/False).", null, 5, false, DisplayLevel.Beginner, ControlType.CheckBox, "", null)]
     400    public bool BooleanAsNumeric
     401    {
     402        get { return booleanAsNumeric; }
     403        set
     404        {
     405            if (value != booleanAsNumeric)
     406            {
     407                booleanAsNumeric = value;
     408                hasChanges = true;
     409                OnPropertyChanged("BooleanAsNumeric");
     410            }
     411        }
     412    }
     413
    396414    private bool flushOnPreExecution = true;
    397     [ContextMenu("Flush text on PreExec", "Flush all text boxes on PreExecution call.", 5, DisplayLevel.Beginner, ContextMenuControlType.CheckBox, null, new string[] {"Flush text on PreExec"})]
    398     [TaskPane("Flush text on PreExec", "Flush all text boxes on PreExecution call.", null, 5, false, DisplayLevel.Beginner, ControlType.CheckBox, null)]
     415    [ContextMenu("Flush text on PreExec", "Flush all text boxes on PreExecution call.", 6, DisplayLevel.Beginner, ContextMenuControlType.CheckBox, null, new string[] {"Flush text on PreExec"})]
     416    [TaskPane("Flush text on PreExec", "Flush all text boxes on PreExecution call.", null, 6, false, DisplayLevel.Beginner, ControlType.CheckBox, null)]
    399417    public bool FlushOnPreExecution
    400418    {
     
    405423        {
    406424          flushOnPreExecution = value;
     425          hasChanges = true;
    407426          OnPropertyChanged("FlushOnPreExecution");
    408427        }
  • trunk/CrypPlugins/XORBinary/XORBinary.cs

    r289 r296  
    233233
    234234        #region Public variables
    235         public int inputOneFlag = -1;
    236         public int inputTwoFlag = -1;
     235        public int inputOneFlag;
     236        public int inputTwoFlag;
    237237        #endregion
    238238
     
    308308        public void Initialize()
    309309        {
    310             // set both inputs dirty
    311             inputOneFlag = -1;
    312             inputTwoFlag = -1;
     310            // set input flags according to settings
     311            if (settings.FlagInputOne) inputOneFlag = 1;
     312            else inputOneFlag = -1;
     313            if (settings.FlagInputTwo) inputTwoFlag = 1;
     314            else inputTwoFlag = -1;
    313315        }
    314316
     
    377379        public void Execute()
    378380        {
    379             if (inputOneFlag == 1)
    380             {
    381                 if (inputTwoFlag == 1)
    382                 {
    383                     // flag all inputs as dirty
    384                     inputOneFlag = -1;
    385                     inputTwoFlag = -1;
    386 
    387                     output = inputOne ^ inputTwo;
    388                     OnPropertyChanged("Output");
    389                 }
     381            if (inputOneFlag == 1 && inputTwoFlag == 1)
     382            {
     383                // flag all inputs as dirty
     384                inputOneFlag = -1;
     385                inputTwoFlag = -1;
     386
     387                output = inputOne ^ inputTwo;
     388                OnPropertyChanged("Output");
    390389            }
    391390        }
  • trunk/CrypPlugins/XORBinary/XORBinarySettings.cs

    r286 r296  
    240240        }
    241241
     242        bool flagInputOne;
     243        [ContextMenu("Declare Flag I1 clean", " yes / no ", 0, DisplayLevel.Beginner, ContextMenuControlType.CheckBox, null, "Set Flag of Input One to clean at the beginning of the chain.")]
     244        [TaskPaneAttribute("Declare Flag I1 clean", " yes / no ", "", 0, false, DisplayLevel.Beginner, ControlType.CheckBox, null)]
     245        public bool FlagInputOne
     246        {
     247            get { return this.flagInputOne; }
     248            set
     249            {
     250                this.flagInputOne = value;
     251                OnPropertyChanged("FlagInputOne");
     252                HasChanges = true;
     253            }
     254
     255        }
     256
     257        bool flagInputTwo;
     258        [ContextMenu("Declare Flag I2 clean", " yes / no ", 0, DisplayLevel.Beginner, ContextMenuControlType.CheckBox, null, "Set Flag of Input Two to clean at the beginning of the chain.")]
     259        [TaskPaneAttribute("Declare Flag I2 clean", " yes / no ", "", 0, false, DisplayLevel.Beginner, ControlType.CheckBox, null)]
     260        public bool FlagInputTwo
     261        {
     262            get { return this.flagInputTwo; }
     263            set
     264            {
     265                this.flagInputTwo = value;
     266                OnPropertyChanged("FlagInputTwo");
     267                HasChanges = true;
     268            }
     269
     270        }
     271
    242272        #endregion
    243273
Note: See TracChangeset for help on using the changeset viewer.